我想使用selenium从网页中提取图像。我正在尝试的代码是
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)
它有一些带有java脚本链接的图像。如何提取其中的所有图像。
答案 0 :(得分:0)
您的图片显示在src
标记中,而不在href
标记
下载文件: -
来源: -
How to download an image using Selenium (any version)?
参考: -