Python Selenium - jak stáhnout obrázek (soubor)?

Python Selenium - jak stáhnout obrázek (soubor)?

Níže jsou uvedeny tři z mnoha postupů, jak stáhnout obrázek či soubor při použití Python Selenium.

Kód je vytržený s kontextu - jedná se o část kódu, kdy bylo cílem stáhnout captcha obrázek...

 

        # DOWNLOAD 1
        # download captcha image via src
        img = captchaImageElement.get_attribute('src')
        urllib.request.urlretrieve(img, "captcha.jpg")

        # DOWNLOAD 2
        # create and save screenshot
        with open('screenshot.png', 'wb') as file:
            file.write(captchaImageElement.screenshot_as_png)

        # DOWNLOAD 3
        # downlod via context menu vith pyautogui
        img2 = b.checkElement(captchaImage)
        actionChain = ActionChains(driver)
        actionChain.context_click(img2).perform()
        pyautogui.typewrite(['down','down','enter'])
        time.sleep(1)
        #pyautogui.typewrite('test.jpg')
        pyautogui.typewrite(['enter'])

Jak se ti článek líbil?

Komentáře (0)

Přidat komentář