Python獲取動態驗證碼
阿新 • • 發佈:2021-09-22
登入
def test_01_login(self): driver = webdriver.Chrome() driver.maximize_window() driver.get("http://www.testingedu.com.cn:8000/Home/user/login.html") driver.find_element(By.ID,'username').send_keys("13800138006") driver.find_element(By.ID,'password').send_keys('123456') sleep(3) #擷取頁面 driver.save_screenshot('b.png') #驗證碼元素 y_element = driver.find_element(By.ID,'verify_code_img') #輸出圖片位置和大小 print(y_element.location) print(y_element.size) left = y_element.location['x'] top = y_element.location['y'] right = left + y_element.size['width'] bottom = top + y_element.size['height'] im = Image.open('../b.png') im = im.crop((left,top,right,bottom)) im.save('c.png') code = input('請輸入驗證碼:') driver.find_element(By.ID,'verify_code').send_keys(code) sleep(5) driver.find_element(By.XPATH,'//*[@id="loginform"]/div/div[6]/a').click() sleep(5)