|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from selenium.webdriver.common.by import By
from time import sleep, time, strftime, localtime
from selenium import webdriver
import threading
import time
global wd,user,pwd,login,chaoshi,js,js2,ID
def denglu(lxnum):
wd = webdriver.Chrome(r'D:\python\chromedriver_win32\chromedriver.exe')
wd.get("www.ddddddd")
sleep(5)
wd.implicitly_wait(10) # 设置最大等待时长
chaoshi=wd.find_element(By.CLASS_NAME,'amsdialog_bconfirm')
if chaoshi is not None:
chaoshi.click()
wd.find_element(By.ID,'dologin').click()
wd.switch_to.frame('loginIframe')
wd.find_element(By.ID,'switcher_plogin').click()
user = wd.find_element(By.ID,'u')
pwd = wd.find_element(By.ID,'p')
user.send_keys('user')
pwd.send_keys('passwd')
login = wd.find_element(By.ID,'login_button')
login.click()
sleep(3)
wd.switch_to.default_content()
sleep(2)
if wd.find_element(By.CSS_SELECTOR, '[href="javascript:lx(1);"]') is not None:
# wd.execute_script("$(lx[1]).click()",button)
# print(button.get_attribute('outerHTML'))
js = 'setTimeout(function () {{lx({});$("#min").val(2);$("#max").val(8);$("#cj").click();$("#qrcj").click(); }},1)'.format(
lxnum)
js2 = 'setTimeout(function () {$("#qrcj").click(); },200)'
wd.execute_script(js)
wd.execute_script(js2)
return
def main():
ID=(1,2,5,6,7,9,14,16)
start_threads = [] # 用来存放执行read函数线程的列表
for i in ID : # 创建1个线程用于t(),并添加到start_threads列表
t = threading.Thread(target=denglu,args=[i]) # 执行的函数如果需要传递参数,threading.Thread(target=函数名,args=(参数,逗号隔开))
start_threads.append(t)
for i in range(1,8):
start_threads[i].start()
if __name__ == '__main__':
main()
运行到登录之后的地方,所有浏览器都闪退,不知道是代码有问题还是,有大佬帮忙看看么
本帖最后由 suchocolate 于 2022-1-22 09:38 编辑
没有join,改一下: for i in ID:
t = threading.Thread(target=denglu, args=[i])
start_threads.append(t)
t.start()
for i in start_threads:
i.join()
|
|