花瓣网美女图片爬取

爬虫基础案例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 分钟前
OpenHarmony混合开发实战指南
c语言·python·flutter·vr·visual studio
white-persist22 分钟前
【攻防世界】reverse | re1-100 详细题解 WP
c语言·开发语言·网络·汇编·python·算法·网络安全
CHANG_THE_WORLD24 分钟前
Python 中的循环结构详解
开发语言·python·c#
quikai19811 小时前
python练习第一组
开发语言·python
谷粒.1 小时前
测试数据管理难题的7种破解方案
运维·开发语言·网络·人工智能·python
深蓝电商API1 小时前
爬虫+大模型结合:让AI自动写XPath和清洗规则
人工智能·爬虫
寒山李白1 小时前
关于Python版本与supervisor版本的兼容性
windows·python·supervisord
梨落秋霜1 小时前
Python入门篇【基础语法】
开发语言·python
ada7_2 小时前
LeetCode(python)——543.二叉树的直径
数据结构·python·算法·leetcode·职场和发展
小白学大数据2 小时前
Python 多线程爬取社交媒体品牌反馈数据
开发语言·python·媒体