urlencoding values in urllib

This is the place for queries that don't fit in any of the other categories.

urlencoding values in urllib

Postby metulburr » Thu Jun 27, 2013 2:49 pm

I must of forgot a step, but it doesnt look it when i compare it to examples. I am trying to input a value into the search field. But the webpage opens with the default value instead of the one i gave. What did i forget?

Code: Select all
from urllib.request import urlopen, Request
from urllib.parse import urlencode

def open_in_browser(doc):
    import webbrowser as WB
    f = open('test.html', 'w')

url = 'http://www.webmd.com/diet/healthtool-food-calorie-counter'

values = {

data = urlencode(values).encode()
req = Request(url, data)
res = urlopen(req)
html = res.read().decode()

we will be moving to python-forum.io on October 1 2016
more details here
User avatar
Posts: 2242
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 4 guests