本文主要是介绍花瓣网美女图片爬取,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
爬虫基础案例01
花瓣网美女图片
网站url:https://huaban.com
图片爬取
import requests
import json
import os
res = requests.get(url= "https://api.huaban.com/search/file?text=%E7%BE%8E%E5%A5%B3&sort=all&limit=40&page=1&position=search_pin&fields=pins:PIN,total,facets,split_words,relations,rec_topic_material"
)json_list = json.loads(res.text)["pins"];url_list = []
for item in json_list:url = "https://gd-hbimg.huaban.com/" + item["file"]["key"] + "_fw480webp"url_list.append(url)print(url_list)
request请求也可用params传递参数:
res = requests.get(url= "https://api.huaban.com/search/file",params={"text":"美女+性感","sort":"all","limit":"100","page":"1","position":"search_pin","fields":"pins:PIN,total,facets,split_words,relations,rec_topic_material"}
)
下载到本地
for i in range(len(url_list)):path_name = "E:\pythonProject\images\\" + str(i) + ".webp"print(path_name)response = requests.get(url_list[i]);with open(path_name,"wb") as f:f.write(response.content)
查看照片:
这篇关于花瓣网美女图片爬取的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!