Proxy with urllib2

前端 未结 7 1560
借酒劲吻你
借酒劲吻你 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 17:50

    In Addition to the accepted answer: My scipt gave me an error

    File "c:\Python23\lib\urllib2.py", line 580, in proxy_open
        if '@' in host:
    TypeError: iterable argument required
    

    Solution was to add http:// in front of the proxy string:

    proxy = urllib2.ProxyHandler({'http': 'http://proxy.xy.z:8080'})
    opener = urllib2.build_opener(proxy)
    urllib2.install_opener(opener)
    urllib2.urlopen('http://www.google.com')
    

提交回复
热议问题