1

I would like to extract the images from webpage using selenium. the code which I am trying is

import os
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
driver = webdriver.Ie()
url_database =  "https://www-nass.nhtsa.dot.gov/nass/cds/CaseForm.aspx?xsl=main.xsl&CaseID=773013618"
driver.get(url_database)
driver.switch_to.frame(driver.find_element_by_id('menu'))
element = driver.find_elements_by_xpath("//a[@class='menu' and contains(@onclick,'toggleswitch(this)') and contains(.,'Front') and contains(@href,'javascript')]")[0]
driver.execute_script("arguments[0].click();", element)
driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_id('menu'))

soup = BeautifulSoup(driver.page_source, "lxml")
for link in soup.findAll('href'):
    print(link)

it has some images with java script link. how to extract all the images in that.

surendra
  • 551
  • 3
  • 13
  • 27

1 Answers1

0

Your image on page is present in src tag not in href tag

Download file :-

  1. Get the SRC attribute of the image.
  2. Use ImageIO.read to read the image onto a BufferedImage
  3. Save the BufferedImage using ImageIO.write function

source :-

How to download an image using Selenium (any version)?

refer :-

enter image description here

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125