背景:通过python脚本多线程从《https://wallhaven.cc》壁纸网站批量下载图片,如果下载其它站点请调整html结构。
系统环境:windows10
python版本:3.8
完整脚本如下:
import time
from queue import Queue
from requests_html import HTMLSession
import requests
import threading
now = time.time()
get_links_list = []
session = HTMLSession()
url_1 = 'https://wallhaven.cc/search?q=id%3A24972&sorting=random&ref=fp&seed=WbEycL&page=2'
urls2 = 'https://wallhaven.cc/search?q=id%3A24972&sorting=random&ref=fp&seed=WbEycL&page='
page_number = 30
def save_image(url, title):
img_response = requests.get(url)
with open('.\Wallpapers\\'+title+'.png', 'wb') as file:
file