-2

My code looks like this at the moment:

captcha_img = driver.find_element_by_class_name('ng-star-inserted')

I want to download the image.

Please help.

  • Please share your code and URL so that we can help you better. Moreover, do some research before asking questions here. Help yourself with below link - https://stackoverflow.com/questions/17361742/download-image-with-selenium-python – Swaroop Humane Jul 26 '20 at 15:23

1 Answers1

0

Another option (we get the url address from the src attribute, then we download and write the file):

Imports :

import requests
from PIL import Image

Code :

url= driver.find_element_by_class_name('ng-star-inserted').get_attribute("src")
img = Image.open(requests.get(url, stream = True).raw)
img.save('image.jpg')

Reference : https://pillow.readthedocs.io/en/4.2.x/releasenotes/2.8.0.html#id1

E.Wiest
  • 5,425
  • 2
  • 7
  • 12