Python基于scrapy采集數(shù)據(jù)時使用代理服務器的方法
更新時間:2015年04月16日 11:27:08 作者:pythoner
這篇文章主要介紹了Python基于scrapy采集數(shù)據(jù)時使用代理服務器的方法,涉及Python使用代理服務器的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了Python基于scrapy采集數(shù)據(jù)時使用代理服務器的方法。分享給大家供大家參考。具體如下:
# 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程序設計有所幫助。
相關文章
Python .py生成.pyd文件并打包.exe 的注意事項說明
這篇文章主要介紹了Python .py生成.pyd文件并打包.exe 的注意事項說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03numpy中的隨機打亂數(shù)據(jù)方法np.random.shuffle解讀
這篇文章主要介紹了numpy中的隨機打亂數(shù)據(jù)方法np.random.shuffle解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05