After the post method, because of the dynamic value back to the value it again with this on webdriver resolved, but the picture on the download link will open a new open, leading to a web page that is different from the picture synchronization code verification, no way can only think of a stupid nothing, screenshots, alas! Because it is only a verification code so only on the question to get the code verification code, others have to download the code a change in Section VI on the line.
from PIL import Image from selenium import webdriver import time from selenium.webdriver.common.keys import Keys # 截全屏 def get_snap(driver): driver..maximize_window(); time.sleep(3) driver.get_screenshot_as_file('./full_snap.png') page_snap_obj = Image.open('full_snap.png') return page_snap_obj def get_image(driver): driver.find_element_by_id ( ' frm_login ' ) .send_keys (Keys.DOWN) # If pages are crawled iframe, switch to the corresponding xpath iframe, not, the following line of code can be annotated driver.switch_to.frame (driver.find_element_by_id ( " frm_login " )) driver.find_element_by_id ( " txt_sdertfgsadscxcadsads " ) .click () # here click input box codes appear codes the time.sleep (2 ) IMG = driver.find_element_by_id ( ' imgCode ' ) LOCA = IMG. LOCATION LOCA [ ' X ' ] = 190 LOCA [ ' Y '] = 190 Print (LOCA) size = img.size # here be adjusted according to their site crawling without the iframe, no need to manually adjust the left = LOCA [ ' X ' ] + 10 Top = LOCA [ ' Y ' ] 107 + right = left + size [ ' width ' ] bottom = Top + size [ ' height ' ] page_snap_obj = get_snap (Driver) page_snap_obj.show () image_obj = page_snap_obj.crop ((left, Top, right, bottom)) image_obj .show () # get the verification code is return image_obj IF __name__ == " __main__ " : Driver = webdriver.Firefox () url = " HTTP: xxxxxxxxxxxxxxxxxxx " # grab verification code website driver.get (url) get_image (Driver)
When the cut was in full-screen because full-screen iframe issue of interception of some problems in the online search, I found a crawling with the same site code id my brother, so I used to come by.
This link: https://blog.csdn.net/qq_34525938/article/details/88945788
----------------
Disclaimer: This article is CSDN blogger "wap2017" original articles follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_34525938/article/details/88945788