Python error when using urllib.open

后端 未结 3 1853
逝去的感伤
逝去的感伤 2020-12-09 08:58

When I run this:

import urllib

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

print feed

I get this output in the interactive window (Py

相关标签:
3条回答
  • 2020-12-09 09:33

    Try this:

    print feed.read()

    See Python docs here.

    0 讨论(0)
  • 2020-12-09 09:43

    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()
    
    0 讨论(0)
  • 2020-12-09 09:46

    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)
    
    0 讨论(0)
提交回复
热议问题