Lio*_*nel 3 python django proxy http-authentication scrapy
我可以使用request.meta ['proxy']设置http代理,但如何验证代理?
这不适用于指定用户和传递:
request.meta['proxy'] = 'http://user:pass@123.456.2323:2222'
Run Code Online (Sandbox Code Playgroud)
从四处查看,我可能必须发送request.headers ['Proxy-Authorization'],但我发送的是什么格式?
用户名和密码是base64编码形式的"username:password"
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3234 次 |
| 最近记录: |