Python urllib urlretrieve behind proxy

前端 未结 2 1562
逝去的感伤
逝去的感伤 2021-01-20 14:52

I looked into the documentation of urllib but all I could find on proxies was related to urlopen. However, I want to download a PDF from a given URL and store it locally but

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-20 15:26

    You've got the right idea you're just missing a few things.

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

提交回复
热议问题