[Python] Download image with selenium python

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I want get captcha image from browser. I have got a url of this picture, but the this picture changes each updated time (url is constant).

    Is there any solution to get picture from browser (like 'save picture as' button)?

    From the other hand, I think it should be work:

    1. get screenshot of the browser
    2. get position of picture
    3. crop captcha from screenshot using opencv

    link of the dynamic capcha - link

    The problem was solved via screenshot:

    browser.save_screenshot('screenshot.png')
    img = browser.find_element_by_xpath('//*[@id="cryptogram"]')
    loc = img.location

    image = cv.LoadImage('screenshot.png', True)
    out = cv.CreateImage((150,60), image.depth, 3)
    cv.SetImageROI(image, (loc['x'],loc['y'],150,60))
    cv.Resize(image, out)
    cv.SaveImage('out.jpg', out)


    Thanks

    Continue reading...

Compartilhe esta Página