Proxy with urllib2

前端 未结 7 1591
借酒劲吻你
借酒劲吻你 2020-11-22 17:15

I open urls with:

site = urllib2.urlopen(\'http://google.com\')

And what I want to do is connect the same way with a proxy I got somewhere telli

7条回答
  •  再見小時候
    2020-11-22 18:04

    To use the default system proxies (e.g. from the http_support environment variable), the following works for the current request (without installing it into urllib2 globally):

    url = 'http://www.example.com/'
    proxy = urllib2.ProxyHandler()
    opener = urllib2.build_opener(proxy)
    in_ = opener.open(url)
    in_.read()
    

提交回复
热议问题