2017-11-29 1 views
0

일반 배경 :어떻게 requests.Session() 객체의 프록시를 변경합니까?

나는 프록시의 목록을 가지고 있고, 나는 PDF URL의 목록을 가지고있다. 나는이 PDF 파일을 다운로드 중이다.

다운로드마다 프록시를 전환 할 수 있기를 원합니다.

몇 가지 답변에서 다음을 보았지만 한 번에 사용 된 모든 프록시입니까? 아니면 프록시의 딕트에서 임의로 선택합니까? 사용할 프록시를 어떻게 선택합니까? 여기

proxies = { 
    'https': 'http://username:[email protected]:port', 
    'https': 'http://[email protected]:port', 
    'https': 'http://[email protected]:port', 
    'https': 'http://[email protected]:port', 
    'https': 'http://[email protected]:port', 
    'https': 'http://[email protected]: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" 

요청의 프록시를 변경하려면 어떻게해야합니까? Session() 객체? POST 및 GET 모두

프록시를 변경하면 사이트에 다시 로그인 할 필요가 없습니다.

답변

0

그냥이 내가 현재 사용하고 코드입니다 그들

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 

통해 프록시 목록과 다음 사이클을 그리고 내가 가졌다 내 문제를 해결했다. 12/13/2017

관련 문제