不啰嗦了直接上源码吧相信大家不喜欢听这些:
import requests
from concurrent.futures import ThreadPoolExecutor
pool = ThreadPoolExecutor(5)
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.46',
}
def mage_url(params):
url = 'https://api.huaban.com/search'
response = requests.get(url=url, headers=headers, params=params)
for url_get in response.json()['pins']:
image_url = f"https://gd-hbimg.huaban.com/{url_get['file']['key']}_fw658webp"
name = url_get['user']['username']
image_list = requests.get(url=image_url, headers=headers).content
with open(f'花瓣素材\{name}.jpg', 'wb') as f:
f.write(image_list)
print(f"{name}保存成功")
if __name__ == '__main__':
for i in range(1,11):
params = {
'q': '美女壁纸',
'sort': 'all',
'per_page': 20,
'page': f"{i}",
'hide_other_count': 1,
'position': 'search_pin',
}
pool.submit(mage_url, params)
pool.shutdown(True)
5.爬取结果如下: