为了账号安全,请及时绑定邮箱和手机立即绑定

Selenium:如何从网站中提取所有图像

Selenium:如何从网站中提取所有图像

largeQ 2022-12-20 10:44:32
我需要使用Selenium从网站中提取所有图像。这应该包括来自 html、css 和 javascript 的任何扩展名(png、jpg、svg等)的所有图像。这意味着简单地提取所有<img>元素是不够的(例如,将丢失任何从 css 样式加载的图像):images = driver.find_elements_by_tag_name('img')  # not sufficient除了下载和解析网站所需的每个 css 和 javascript 脚本并使用正则表达式查找图像文件之外,还有什么更聪明的做法吗?如果有一种方法可以在页面加载后只查找下载的资源,那将是理想的,类似于中的network选项卡chrome dev tools:
查看完整描述

1 回答

?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

答案最初取自How to access Network panel on google chrome developer tools with selenium? . 我刚刚更新了一点。


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


查看完整回答
反对 回复 2022-12-20
  • 1 回答
  • 0 关注
  • 130 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信