2017-11-29 13 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

関連する問題