花瓣网美女图片爬取

爬虫基础案例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)

查看照片:

相关推荐
shx66667 分钟前
2.2.1 ROS2 在功能包中编写 Python 节点
开发语言·python·ros2
beijingliushao9 分钟前
100-Spark Local模式部署
大数据·python·ajax·spark
BoBoZz1911 分钟前
TessellatedBoxSource 创建并渲染一个细分的、可移动的箱体模型
python·vtk·图形渲染·图形处理
weixin_4573402123 分钟前
旋转OBB数据集标注查看器
图像处理·人工智能·python·yolo·目标检测·数据集·旋转
nvd1132 分钟前
LLM 对话记忆功能实现深度解析
python
电饭叔42 分钟前
Luhn算法初介绍
python
badmonster01 小时前
实时代码库索引:用 CocoIndex 构建智能代码搜索的终极方案
python·rust
晓山清1 小时前
Meeting Summarizer Using Natural Language Processing论文理解
人工智能·python·nlp·摘要生成
zqy02271 小时前
python安装与环境配置
开发语言·python
Wise玩转AI1 小时前
从LLM到Agent:技术迁移的必然趋势
人工智能·python·语言模型·ai智能体