[英]How can I make each window open with different proxy selenium
因此,我有此脚本可以打开“链接”数组中的每个项目。 但是,我希望使用不同的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()
任何帮助是极大的赞赏。 谢谢
Selenium官方网站的答案: 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)
如果您的代理需要身份验证并接受基本HTTP身份验证 ,则可以尝试以下格式的代理:
http://user:password@proxyurl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.