要从Firefox WebDriver获取图像详细信息,您可以使用Python编程语言和Selenium库。以下是一个简单的示例代码,说明如何获取页面上所有图像的详细信息,如宽度、高度、大小和URL。
pip install selenium
image_details.py
,并将以下代码粘贴到其中:from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from PIL import Image
import io
import requests
def get_image_details(url):
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get(url)
images = driver.find_elements_by_tag_name('img')
for image in images:
src = image.get_attribute('src')
width = image.get_attribute('width')
height = image.get_attribute('height')
size = requests.head(src).headers.get('content-length')
try:
size = int(size) / (1024 * 1024) # Convert to MB
except TypeError:
size = None
print(f"URL: {src}")
print(f"Width: {width}")
print(f"Height: {height}")
print(f"Size (MB): {size}")
# 下载并获取图像详细信息
response = requests.get(src)
img = Image.open(io.BytesIO(response.content))
print(f"Image Mode: {img.mode}")
print(f"Image Format: {img.format}")
print(f"Image Size: {img.size}")
get_image_details("https://example.com")
https://example.com
替换为您要获取图像详细信息的网站URL。image_details.py
文件,您将看到每个图像的详细信息,包括URL、宽度、高度、大小和图像模式、格式和尺寸。请注意,此示例代码仅适用于公共网站。对于需要登录的网站,您可能需要使用Selenium的其他功能来模拟用户交互,例如单击按钮、输入用户名和密码等。
领取专属 10元无门槛券
手把手带您无忧上云