Skip to content Skip to sidebar Skip to footer

Python Error When Using Urllib.open

When I run this: import urllib feed = urllib.urlopen('http://www.yahoo.com') print feed I get this output in the interactive window (PythonWin):

Solution 1:

Try this:

print feed.read()

See Python docs here.

Solution 2:

urllib.urlopen actually returns a file-like object so to retrieve the contents you will need to use:

import urllib

feed = urllib.urlopen("http://www.yahoo.com")

print feed.read()

Solution 3:

In python 3.0:

import urllib
import urllib.request

fh = urllib.request.urlopen(url)
html = fh.read().decode("iso-8859-1")
fh.close()

print (html)

Post a Comment for "Python Error When Using Urllib.open"