1 from selenium import webdriver 2 import time 3 4 driver = webdriver.Chrome(r'D:BaiduNetdiskDownloadchromedriver_win32chromedriver.exe') 5 6 # 把窗口转成全屏 7 driver.maximize_window() 8 9 try: 10 driver.get('https://dig.chouti.com/') 11 driver.implicitly_wait(10) 12 time.sleep(5) 13 14 # 1、点击登录 15 login_btn = driver.find_element_by_id('login_btn') 16 login_btn.click() 17 time.sleep(2) 18 19 # 2、输入用户名 20 phone = driver.find_element_by_class_name('login-phone') 21 phone.send_keys('15622792660') 22 23 # 3、输入密码 24 pwd = driver.find_element_by_class_name('pwd-password-input') 25 pwd.send_keys('kermit46709394') 26 27 # 4、确认登录 28 login_submit = driver.find_element_by_class_name('btn-large') 29 login_submit.click() 30 31 time.sleep(20) 32 33 # 捕获异常并打印 34 except Exception as e: 35 print(e) 36 37 finally: 38 driver.close()