花瓣网美女图片爬取

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

查看照片:

相关推荐
哈里谢顿13 小时前
Django 应用 OOM(Out of Memory)故障的定位思路和排查方法
python·django
甄心爱学习13 小时前
【python】获取所有长度为 k 的二进制字符串
python·算法
tuotali202614 小时前
氢气压缩机技术规范亲测案例分享
人工智能·python
嫂子的姐夫14 小时前
030-扣代码:湖北图书馆登录
爬虫·python·逆向
a11177615 小时前
EasyVtuber(或其衍生/增强版本)的虚拟主播(Vtuber)面部动画生成与直播解决方案
python·虚拟主播
lintax15 小时前
计算pi值-积分法
python·算法·计算π·积分法
小凯1234515 小时前
pytest框架-详解(学习pytest框架这一篇就够了)
python·学习·pytest
逻极15 小时前
pytest 入门指南:Python 测试框架从零到一(2025 实战版)
开发语言·python·pytest