Changing user agent on urllib2.urlopen

后端 未结 9 2264
感动是毒
感动是毒 2020-11-22 13:59

How can I download a webpage with a user agent other than the default one on urllib2.urlopen?

9条回答
  •  醉话见心
    2020-11-22 15:02

    For python 3, urllib is split into 3 modules...

    import urllib.request
    req = urllib.request.Request(url="http://localhost/", headers={'User-Agent':' Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'})
    handler = urllib.request.urlopen(req)
    

提交回复
热议问题