花瓣网美女图片爬取

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

查看照片:

相关推荐
飞Link18 小时前
pprint 全量技术手册:复杂数据结构的结构化输出引擎
开发语言·前端·python
培风图南以星河揽胜18 小时前
幻想简历!博主本人期望的 AI Agent 全栈简历:Java + Python + Vue3 跨语言实战,代码已开源!
java·人工智能·python
第一程序员18 小时前
Python函数式编程:非科班转码者的入门指南
python·github
蓝色的杯子18 小时前
龙虾-OpenClaw一文详细了解-手搓OpenClaw-2 Provider层
人工智能·python
AI_Claude_code18 小时前
ZLibrary访问困境方案二:DNS-over-HTTPS/TLS配置与隐私保护实践
爬虫·python·网络协议·http·网络安全·https·网络爬虫
至此流年莫相忘19 小时前
数据库迁移工具——Alembic
python
Dxy123931021619 小时前
Python有哪些方法可以进行文本纠错
开发语言·python
却道天凉_好个秋19 小时前
pytorch(一):张量
人工智能·pytorch·python·深度学习
华清远见IT开放实验室19 小时前
AI 算法核心知识清单(深度实战版1)
人工智能·python·深度学习·学习·算法·机器学习·ai
百结21419 小时前
Python网络编程
网络·python