第一部分 requests , ChromeDriver, PhantomJS的代理IP使用
1-1 requests使用代理IP
http = 'http://'+str(ip)
proxies = {
"http": http
}
try:
r = requests.get("http://blog.csdn.net/qq_36962569/article/details/77387299", proxies=proxies)
except Exception as e:
print(+e)
同理,requests模塊添加headers ,cookies ,data,可以直接
requests.get(url,headers=headers)
requests.get(url,cookies=cookies
requests.get(url,data=data)
也可以傳遞多個參數,
requests.get(url,headers=headers,data=data)
參考鏈接:
Python 筆記七:Requests爬蟲技巧(隆重推出,十分詳細)
Python爬蟲技巧—設置代理IP
1-2 ChromeDriver使用代理IP
def ChromeDriverWithIP():
PROXY = "47.52.108.18"
chrome_options = webdriver.ChromeOptions()
# 兩種用法添加代理IP
# chrome_options.add_argument('--proxy-server=http://35.189.128.127')
chrome_options.add_argument('