作者:漢學
原創作品,轉載請保留出處 www.cnblogs.com/c2soft
使用selenium時,不少登錄操作需要識別驗證碼,這部分操作可以交給人工完成,待人工操作完成后再由 selenium 接管自動操作。
from selenium import webdriver WEB_TITLE = "我的百度網盤" wb = webdriver.Chrome() wb.get("https://pan.baidu.com") wait_flag = 1 while(wait_flag): handles = wb.window_handles # 獲取當前窗口句柄集合(列表類型) # 逐個窗口打印標題 for b in handles: wb.switch_to_window(b) #h_id = handles.index(b) #wb.switch_to_window(handles[h_id]) if wb.title == WEB_TITLE: wait_flag = 0 break #print(str(handels.index(b)) + " : " + wb.title + ": " + wb.current_url) print("等待打開登錄后的頁面...") time.sleep(5) while(1): delay = random.randint(5, 11) time.sleep(delay) if checkFile(wb) == True: #os.system("tip.mp3") break print("腳本執行完畢")