1. 程式人生 > >Request和Urllib2使用代理ip的區別

Request和Urllib2使用代理ip的區別


proxies = {'http':'http://XX.XX.XX.XX:XXXX'} Requests:   import requests   response = requests.get(url=url, proxies=proxies)
Urllib2:   import urllib2   proxy_support = urllib2.ProxyHandler(proxies) 
 opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)   urllib2.install_opener(opener) # 安裝opener,此後呼叫urlopen()時都會使用安裝過的opener物件 response = urllib2.urlopen(url)  response =urllib2.urlopen(url)