我可以使用 request.meta['proxy'] 设置一个 http 代理,但我如何验证代理?
这对指定用户和密码不起作用:
request.meta['proxy'] = 'http://user:pass@123.456.2323:2222'
环顾四周,我可能必须发送 request.headers['Proxy-Authorization'],但我应该以什么格式发送它?
最佳答案
用户名和密码以“用户名:密码”的形式进行base64编码
import base64
# Set the location of the proxy
proxy_string = choice(self._get_proxies_from_file('proxies.txt')) # user:pass@ip:port
proxy_items = proxy_string.split('@')
request.meta['proxy'] = "http://%s" % proxy_items[1]
# setup basic authentication for the proxy
user_pass=base64.encodestring(proxy_items[0])
request.headers['Proxy-Authorization'] = 'Basic ' + user_pass
关于python - 验证 Scrapy HTTP 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8203093/