urllib.request in Python 2.7

后端 未结 3 1521
生来不讨喜
生来不讨喜 2020-12-05 03:27

I can use urllib.request module with Python 3.1. But when I execute the same program using Python 2.7, an error comes along the lines of;

AttributeError: \'module         


        
相关标签:
3条回答
  • 2020-12-05 03:39

    use urllib2.urlopen

    0 讨论(0)
  • 2020-12-05 03:42

    It is also possible to use six module to make code for both python2 & python3:

    from six.moves import urllib
    # ...
    result = urllib.request.urlopen(url)
    
    0 讨论(0)
  • 2020-12-05 04:00

    Take a look at http://docs.python.org/library/urllib2.html.

    The urllib2 module is the predecessor to urllib.request/urllib.error (it has been split into those modules in Python 3.0).

    0 讨论(0)
提交回复
热议问题