我想在Mutiprocessing池中用Chrome
打开更多selenium
窗口。现在,打开了窗口,但未运行编程。
这是我的代码,如下所示:
import time
from PIL import Image
from selenium.common.exceptions import TimeoutException
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from threading import Thread,Event
from multiprocessing import Process,Pool
from cookiesinterpark.cookiespool.db import *
class interpark():
def __init__(self,account,password):
self.account = account
self.password = password
self.browser = webdriver.Chrome()
self.url ='https://ticket.interpark.com/Gate/TPLogin.asp?CPage=B&MN=Y&tid1=main_gnb&tid2=right_top&tid3=login&tid4=login'
self.wait = WebDriverWait(self.browser, 20)
def login(self):
self.browser.maximize_window()
self.browser.delete_all_cookies()
self.browser.get(self.url)
username = self.wait.until(EC.presence_of_element_located((By.ID, 'UID')))
password = self.wait.until(EC.presence_of_element_located((By.ID, 'PWD')))
username.send_keys(self.account)
password.send_keys(self.password)
self.browser.execute_script("javascript:login();")
try:
alert = self.browser.switch_to_alert()
if alert:
alert.accept()
print('{}:'.format(self.account))
self.DealCaptcha()
else:
pass
except:
pass
def run(self):
self.login()
if __name__ == '__main__':
pool = Pool(processes=3)
cnn = RedisClient('account', 'interpark')
accounts_usernames = cnn.usernames()
for username in accounts_usernames:
password = cnn.get(username)
p = pool.apply_async(interpark, args=(username,password))
pool.close()
pool.join()
我收到以下错误:
Traceback (most recent call last):
File "D:/PycharmProjects/interparkOK/cookiesinterpark/login/interpark/Captcha/interparktest.py", line 152, in <module>
p = pool.apply_async(interpark, args=(username,password))
File "C:\Python36\lib\multiprocessing\pool.py", line 355, in apply_async
raise ValueError("Pool not running")
ValueError: Pool not running
我考虑过Threading
来解决此问题,但是在考虑有关selenium webdriver
的问题时,似乎它不支持多线程。
我该如何解决?
答案 0 :(得分:0)
从您的代码中尝试
if __name__ == '__main__':
pool = Pool(processes=3)
cnn = RedisClient('account', 'interpark')
accounts_usernames = cnn.usernames()
for username in accounts_usernames:
password = cnn.get(username)
p = pool.apply_async(interpark, args=(username,password))
pool.close() # deindented
pool.join() # deindented
您遇到了该错误,因为您在for循环中关闭了池。