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()

New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
User avatar
Posts: 1122
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], tnknepp and 2 guests