2. 手动与半自动化方法
对于少量图片下载需求,可以直接右键任意图片链接,选择“在新标签页中打开”,然后使用浏览器的“另存为”功能保存。然而,当面对大量图片时,这种方法效率较低。
为了提高效率,可以复制图片地址并借助外部工具或脚本进行自动化处理。例如,使用Python编写一个简单的脚本来批量下载图片:
import requests
from bs4 import BeautifulSoup
url = "目标网页URL"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
for img in soup.find_all('img'):
img_url = img['src']
img_data = requests.get(img_url).content
with open(img_url.split('/')[-1], 'wb') as handler:
handler.write(img_data)