Python基于scrapy采集数据时使用代理服务器的方法
本文实例讲述了Python基于scrapy采集数据时使用代理服务器的方法。分享给大家供大家参考。具体如下:
#Toauthenticatetheproxy, #youmustsettheProxy-Authorizationheader. #You*cannot*usetheformhttp://user:pass@proxy:port #inrequest.meta['proxy'] importbase64 proxy_ip_port="123.456.789.10:8888" proxy_user_pass="awesome:dude" request=Request(url,callback=self.parse) #Setthelocationoftheproxy request.meta['proxy']="http://%s"%proxy_ip_port #setupbasicauthenticationfortheproxy encoded_user_pass=base64.encodestring(proxy_user_pass) request.headers['Proxy-Authorization']='Basic'+encoded_user_pass
希望本文所述对大家的python程序设计有所帮助。
热门推荐
2 红丝绒戚风蛋糕
3 夹心小甜点
4 南瓜甜点
6 粘米粉蒸蛋糕
7 酸奶华夫饼
9 红柚鸡蛋糕
10 葡萄干蛋糕
11 紫薯蛋糕卷
13 纸杯裱花小蛋糕
14 果酱奶酪蛋糕
15 日式樱花蔓越莓大福
16 草莓蛋糕卷
17 卡仕达长崎杯子蛋糕