花瓣网美女图片爬取

爬虫基础案例01

花瓣网美女图片

网站url:https://huaban.com

图片爬取

python 复制代码
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传递参数:

python 复制代码
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"
    }
)

下载到本地

python 复制代码
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)

查看照片:

相关推荐
wfeqhfxz2588782几秒前
条形码识别与定位:基于FCOS框架的多类型条码检测与识别技术详解
python
free-elcmacom1 分钟前
Python实战项目<3>赛制分数分析
开发语言·前端·python·数据分析
赵谨言2 分钟前
基于OpenCV的数字识别系统
大数据·开发语言·经验分享·python
sugar椰子皮2 分钟前
【node阅读-0】下载编译node
爬虫
飞天小蜈蚣1 小时前
http协议和django初识
python
路边草随风1 小时前
langchain agent动态变更系统prompt
人工智能·python·langchain·prompt
哥本哈士奇(aspnetx)8 小时前
Streamlit + LangChain 1.0 简单实现智能问答前后端
python·大模型
我一定会有钱8 小时前
斐波纳契数列、end关键字
python
小鸡吃米…9 小时前
Python 列表
开发语言·python
星依网络10 小时前
yolov5实现游戏图像识别与后续辅助功能
python·开源·游戏程序·骨骼绑定