簡體   English   中英

Selenium:如何從網站中提取所有圖像(包括來自 javascript 和 css 的圖像)

[英]Selenium: how to extract all images from a website (including ones from javascript and css)

我需要使用Selenium從網站中提取所有圖像。 這應該包括來自pngjpg svg和 ZDE9B9ED708D7E9119DCEE.FF9ED708D7E911E78 這意味着簡單地提取所有<img>元素是不夠的(例如,任何從 css 樣式加載的圖像都將丟失):

images = driver.find_elements_by_tag_name('img')  # not sufficient

有什么比下載和解析網站所需的每個 css 和 javascript 腳本並使用正則表達式查找圖像文件更聰明的方法嗎?

如果有一種方法可以在頁面加載后查找下載的資源,這將是理想的,類似於chrome dev tools中的network選項卡:

在此處輸入圖像描述

任何想法?

答案最初取自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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM