花瓣网美女图片爬取

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

查看照片:

相关推荐
星火开发设计4 分钟前
Python数列表完全指南:从基础到实战
开发语言·python·学习·list·编程·知识·期末考试
星浩AI9 分钟前
LCEL:打造可观测、可扩展、可部署的 LangChain 应用
人工智能·后端·python
这儿有一堆花13 分钟前
Python 虚拟环境的配置与管理指南
开发语言·python
Generalzy18 分钟前
深度觉醒 — Deep Agents(三座大山 — Agent 的核心挑战)
python
彼岸花开了吗29 分钟前
构建AI智能体:七十八、参数的艺术:如何在有限算力下实现高质量的AI诗歌创作
人工智能·python·llm
小途软件29 分钟前
基于深度学习的人脸检测算法研究
java·人工智能·pytorch·python·深度学习·语言模型
guoketg41 分钟前
Vision Transformer(ViT)的讲解和面试题目讲解
人工智能·python·深度学习·vit
小oo呆1 小时前
【学习心得】Python的Pydantic(简介)
前端·javascript·python
岚天start1 小时前
【日志监控方案】Python脚本获取关键字日志信息并推送钉钉告警
python·钉钉·日志监控
叫我:松哥1 小时前
基于 Flask 框架开发的在线学习平台,集成人工智能技术,提供分类练习、随机练习、智能推荐等多种学习模式
人工智能·后端·python·学习·信息可视化·flask·推荐算法