花瓣网美女图片爬取

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

查看照片:

相关推荐
子云之风7 分钟前
LSPosed 项目编译问题解决方案
java·开发语言·python·学习·android studio
小北方城市网7 分钟前
SpringBoot 全局异常处理与接口规范实战:打造健壮可维护接口
java·spring boot·redis·后端·python·spring·缓存
REDcker30 分钟前
Puppeteer 与 Selenium 对比分析
爬虫·selenium·自动化·浏览器·puppeteer
SunnyRivers31 分钟前
打包 Python 项目
python·打包
万行32 分钟前
机器人系统SLAM讲解
开发语言·python·决策树·机器学习·机器人
我的xiaodoujiao32 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 40--完善优化 Allure 测试报告显示内容
python·学习·测试工具·pytest
WinstonJQ33 分钟前
AirSim无人机仿真入门(一):实现无人机的起飞与降落
python·机器人·游戏引擎·ue4·无人机
tjjucheng35 分钟前
专业做小程序定制开发的厂家
python
Hello.Reader41 分钟前
Flink DynamoDB Connector 用 Streams 做 CDC,用 BatchWriteItem 高吞吐写回
大数据·python·flink
gc_22991 小时前
学习python调用dmpython库获取达梦数据库模式信息的基本方式
python·dmpython