一般背景:
我有一个代理列表,我有一个PDF网址列表,我正在下载这些PDF文件。
我希望能够切换代理每两次下载。
我在几个答案中看到了下面的内容,但是所有的代理都是同时使用的吗?或者是从代理中随机产生的?如何选择使用哪个代理?
proxies = {
'https': 'http://username:password@ip:port',
'https': 'http://usernamepassword@ip:port',
'https': 'http://usernamepassword@ip:port',
'https': 'http://usernamepassword@ip:port',
'https': 'http://usernamepassword@ip:port',
'https': 'http://usernamepassword@ip:port'
}下面是我拥有的当前代码的示例
我的代码:
s = requests.Session()
data = {"Username":"usr", "Password":"psw"}
url = "https://someSite.com"
#Logging into the site
s.post(url, data=data) #add proxies=proxies here?
for download_url in PDFLinks:
temp = s.get(download_url).content我有一个可用代理服务器的列表
https_proxy_list = "https://IP:port", "https://IP:port", "https://IP:port"如何更改request.Session()对象的代理?同时发布和获取
通过更改代理,我不需要重新登录到站点,对吗?
发布于 2017-12-13 15:33:16
只要有一个代理列表,然后循环它们。
s = requests.Session()
proxyList = ['Just imagine there are a few proxies here']
for item in proxyList:
r2 = s.get(login_url, proxies = {'https' : item}, verify=False)
print r2.status_code
if r2.status_code == 200:
print "It worked"
usable_IP.append(item)
print usable_IP
print usable_IP这是我目前使用的代码,它解决了我的问题。2017年13/12
https://stackoverflow.com/questions/47561549
复制相似问题