Python基于scrapy采集数据时使用代理服务器的方法,pythonscrapy
Python基于scrapy采集数据时使用代理服务器的方法,pythonscrapy
本文实例讲述了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程序设计有所帮助。
相关内容
- 使用Python编写一个简单的tic-tac-toe游戏的教程,pythont
- scrapy自定义pipeline类实现将采集数据保存到mongodb的方法
- 使用Python的Zato发送AMQP消息的教程,zatoamqp
- 在Python中使用Neo4j数据库的教程,pythonneo4j
- 在Python下利用OpenCV来旋转图像的教程,pythonopencv
- 使用Python脚本来控制Windows Azure的简单教程,pythonazure
- 利用Python中的mock库对Python代码进行模拟测试,pythonmo
- 全面剖析Python的Django框架中的项目部署技巧第1/2页,
- 使用Python编写一个模仿CPU工作的程序,python编写模仿
- 使用Protocol Buffers的C语言拓展提速Python程序的示例,b
评论关闭