Opening Local File Works with urllib but not with urllib2

前端 未结 3 1530
既然无缘
既然无缘 2020-12-30 21:36

I\'m trying to open a local file using urllib2. How can I go about doing this? When I try the following line with urllib:

resp = urllib.urlopen(url)
         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 21:49

    Just put "file://" in front of the path

    >>> import urllib2
    >>> urllib2.urlopen("file:///etc/debian_version").read()
    'wheezy/sid\n'
    

提交回复
热议问题