【发布时间】:2016-07-11 05:37:01
【问题描述】:
我需要知道是否可以为每个驱动程序句柄设置代理/配置文件。 我有以下代码:
def browser(url, id, user1, parolauser1, user2, parolauser2):
print multiprocessing.current_process()
fp = webdriver.FirefoxProfile("C:\Users\yt\AppData\Roaming\Mozilla\Firefox\Profiles\hgv9qvsn.default")
driver = webdriver.Firefox(fp)
driver.get(url)
for handle in driver.window_handles:
if "whateveriwant" in driver.title and id == 0:
...
for catevreaueu in range(0,7000):
test_to_see_how_many_lines_are_in_a_file = function_test_to_see_how_many_lines_are_in_a_file_for_this_first_handle()
print test_to_see_how_many_lines_are_in_a_file
if test_to_see_how_many_lines_are_in_a_file < 3:
another_function_for_continuing_on_this_first_handle(driver)
else:
driver.close()
break
if "whateveriwant" in driver.title and id == 1:
...
for catevreaueu in range(0,7000):
test_to_see_how_many_lines_are_in_a_file = function_test_to_see_how_many_lines_are_in_a_file_for_this_s_handle()
print test_to_see_how_many_lines_are_in_a_file
if test_to_see_how_many_lines_are_in_a_file < 3:
another_function_for_continuing_on_this_second_handle(driver)
else:
driver.close()
break
return
if __name__ == '__main__':
jobs = []
user_one = "userone"
parola_user_one = "passwordforuserone"
user_two = "usertwo"
parola_user_two = "passwordforuser2"
pages = ["http://www.didi.com", "http://www.didi.com/"]
id = 0
for page in pages:
p = multiprocessing.Process(target=browser, args=(page, id, user_one, parola_user_one, user_two, parola_user_two))
id+=1
jobs.append(p)
p.start()
现在它启动了两个 webdriver 实例,但您可以看到它们都使用相同的配置文件。
【问题讨论】:
标签: python python-2.7 selenium webdriver