![](/img/trans.png)
[英]How can count all images on a page with JavaScript (including CSS and img)
[英]Selenium: how to extract all images from a website (including ones from javascript and css)
我需要使用Selenium從網站中提取所有圖像。 這應該包括來自png
、 jpg
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.