2017-09-19 10 views
0

したがって、私は 'link'配列の各項目を開くこのスクリプトを持っています。しかし、私は各ウィンドウを別のip:port:user:passプロキシを使用して開くことを望みます。どのように各ウィンドウを別のプロキシセレニウムで開けるようにすることができます

これは、これまでの私のコードです。

from selenium import webdriver 

def main(): 

# link = "http://www.google.com" 
link = ["www.google.com", "www.wikipedia.com"] 


windows = len(link) 
DRIVERS = [] 
position = [0,0] 
count = 0 
for i in range(0,windows): 
    if count == 1000: 
     count = 0 
     position[0] += 300 

    driver = webdriver.Chrome(executable_path="drivers/chromedriver") 

    driver.set_window_size(300,200) 
    driver.get(link[i]) 
    DRIVERS.append(driver) 
    driver.set_window_position(position[0], position[1]+count) 
    count += 200 

exit = input("exit? ") 
for eachWindow in DRIVERS: 
    eachWindow.quit() 


if __name__ == '__main__': 
    main() 

ご協力いただきまして誠にありがとうございます。セレン公式ウェブサイトからの感謝

答えて

0

回答: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy

for i in range(0,windows): 
    PROXY = "localhost:8080" 

    # Create a copy of desired capabilities object. 
    desired_capabilities = webdriver.DesiredCapabilities.CHROME.copy() 
    # Change the proxy properties of that copy. 
    desired_capabilities['proxy'] = { 
     "httpProxy":PROXY, 
     "ftpProxy":PROXY, 
     "sslProxy":PROXY, 
     "noProxy":None, 
     "proxyType":"MANUAL", 
     "class":"org.openqa.selenium.Proxy", 
     "autodetect":False 
    } 

    # you have to use remote, otherwise you'll have to code it yourself in python to 
    # dynamically changing the system proxy preferences 
    driver = webdriver.Chrome(executable_path="drivers/chromedriver", 
      desired_capabilities=desired_capabilities) 

プロキシ必要性のauthおよびBasic HTTP Authを受け入れるならば、あなたは形式でプロキシを試すことができます。

http://user:[email protected] 
+0

達成するための可能な方法がありますこれはユーザーと一緒に:プロキシを渡しますか? –

+0

プロキシはhttp:// user:password @ proxyurlとして試してください – yong

関連する問題