Selenium:如何从网站中提取所有图像(包括来自javascript和css的图像)
我需要提取所有的图像从一个网站使用。这应该包括来自html、css和javascript的任何扩展(Selenium:如何从网站中提取所有图像(包括来自javascript和css的图像),javascript,python,html,css,selenium,Javascript,Python,Html,Css,Selenium,我需要提取所有的图像从一个网站使用。这应该包括来自html、css和javascript的任何扩展(png、jpg、svg)的所有图像。这意味着仅提取所有元素是不够的(例如,从css样式加载的任何图像都将丢失): images=driver.find_elements_by_tag_name('img')#不够 有什么比下载和解析网站所需的每个css和javascript脚本以及使用正则表达式查找图像文件更聪明的方法吗 如果有一种方法可以在页面加载后查找下载的资源,这将是理想的,类似于chro
png
、jpg
、svg
)的所有图像。这意味着仅提取所有
元素是不够的(例如,从css样式加载的任何图像都将丢失):
images=driver.find_elements_by_tag_name('img')#不够
有什么比下载和解析网站所需的每个css和javascript脚本以及使用正则表达式查找图像文件更聪明的方法吗
如果有一种方法可以在页面加载后查找下载的资源,这将是理想的,类似于chrome-dev-tools
中的network
选项卡:
有什么想法吗?答案最初取自。我只是更新了一点
resources = driver.execute_script("return window.performance.getEntriesByType('resource');")
for resource in resources:
if resource['initiatorType'] == 'img': # check for other types if needed
print(resource['name']) # this is the original link of the file
答案最初来自于。我只是更新了一点
resources = driver.execute_script("return window.performance.getEntriesByType('resource');")
for resource in resources:
if resource['initiatorType'] == 'img': # check for other types if needed
print(resource['name']) # this is the original link of the file