scrapy 带认证的代理
官方方法:
from w3lib.http import basic_auth_header class CustomProxyMiddleware(object): def process_request(self, request, spider): request.meta[‘proxy‘] = "https://<PROXY_IP_OR_URL>:<PROXY_PORT>" request.headers[‘Proxy-Authorization‘] = basic_auth_header( ‘<PROXY_USERNAME>‘, ‘<PROXY_PASSWORD>‘)
DOWNLOADER_MIDDLEWARES = { ‘<PROJECT_NAME>.middlewares.CustomProxyMiddleware‘: 350, ‘scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware‘: 400, }
经过测试,不带认证的这么写也没有问题
相关推荐
andrewwf 2020-11-11
Arvinzx 2020-10-28
CycloneKid 2020-10-27
paleyellow 2020-10-25
baifanwudi 2020-10-25
heyboz 2020-10-21
wumxiaozhu 2020-10-16
ZHANGRENXIANG00 2020-07-27
zhangll00 2020-07-05
javaraylu 2020-06-28
ZHANGRENXIANG00 2020-06-28
Catastrophe 2020-06-26
Catastrophe 2020-06-26
fangjack 2020-06-25
andrewwf 2020-06-16
qyf 2020-06-14
荒乱的没日没夜 2020-06-14