花瓣网美女图片爬取

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

查看照片:

相关推荐
qq_416018723 分钟前
用户认证与授权:使用JWT保护你的API
jvm·数据库·python
王夏奇14 分钟前
笔记-关于python复习
python
AC赳赳老秦23 分钟前
OpenClaw 全平台安装详解:Windows 10/11、macOS、Linux 零踩坑指南 (附一键脚本)
大数据·人工智能·python·django·去中心化·ai-native·openclaw
Eward-an42 分钟前
爬虫对抗:ZLibrary反爬机制实战分析(纯技术研究视角)
爬虫
m0_743297421 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python
databook1 小时前
从直觉到算法:贝叶斯思维的技术底层与工程实现
人工智能·python·机器学习
m0_716667071 小时前
使用PyQt5创建现代化的桌面应用程序
jvm·数据库·python
XW01059991 小时前
6-1输入列表,求列表元素和(eval输入应用)
python
川石课堂软件测试1 小时前
接口测试需要注意的一些BUG
网络·数据库·python·单元测试·bug·压力测试·tornado
2401_853576501 小时前
定时任务专家:Python Schedule库使用指南
jvm·数据库·python