Alex Rivera | Logout

Python error when using urllib.open

Asked 2009-03-01T19:56:54.877
25

When I run this:

import urllib

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

print feed

I get this output in the interactive window (PythonWin):

<addinfourl at 48213968 whose fp = <socket._fileobject object at 0x02E14070>>

I'm expecting to get the source of the above URL. I know this has worked on other computers (like the ones at school) but this is on my laptop and I'm not sure what the problem is here. Also, I don't understand this error at all. What does it mean? Addinfourl? fp? Please help.

Edit
Report

2 Answers

55

Try this:

print feed.read()

See Python docs here.

answered 2009-03-01T20:00:08.600
7

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)
answered 2009-03-01T22:11:58.830

Your Answer