Python基于scrapy采集數據時使用代理服務器的方法
來源:懂視網
責編:小采
時間:2020-11-27 14:32:43
Python基于scrapy采集數據時使用代理服務器的方法
Python基于scrapy采集數據時使用代理服務器的方法:本文實例講述了Python基于scrapy采集數據時使用代理服務器的方法。分享給大家供大家參考。具體如下: # To authenticate the proxy, #you must set the Proxy-Authorization header. #You *cannot* use the form h
導讀Python基于scrapy采集數據時使用代理服務器的方法:本文實例講述了Python基于scrapy采集數據時使用代理服務器的方法。分享給大家供大家參考。具體如下: # To authenticate the proxy, #you must set the Proxy-Authorization header. #You *cannot* use the form h

本文實例講述了Python基于scrapy采集數據時使用代理服務器的方法。分享給大家供大家參考。具體如下:
# To authenticate the proxy,
#you must set the Proxy-Authorization header.
#You *cannot* use the form http://user:pass@proxy:port
#in request.meta['proxy']
import base64
proxy_ip_port = "123.456.789.10:8888"
proxy_user_pass = "awesome:dude"
request = Request(url, callback=self.parse)
# Set the location of the proxy
request.meta['proxy'] = "http://%s" % proxy_ip_port
# setup basic authentication for the proxy
encoded_user_pass=base64.encodestring(proxy_user_pass)
request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass
希望本文所述對大家的python程序設計有所幫助。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Python基于scrapy采集數據時使用代理服務器的方法
Python基于scrapy采集數據時使用代理服務器的方法:本文實例講述了Python基于scrapy采集數據時使用代理服務器的方法。分享給大家供大家參考。具體如下: # To authenticate the proxy, #you must set the Proxy-Authorization header. #You *cannot* use the form h