花瓣网美女图片爬取

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

查看照片:

相关推荐
m0_748252388 分钟前
Ruby 模块(Module)的基本概念
开发语言·python·ruby
子午16 分钟前
【2026原创】水稻植物病害识别系统~Python+深度学习+人工智能+resnet50算法+TensorFlow+图像识别
人工智能·python·深度学习
深蓝电商API19 分钟前
Scrapy ImagesPipeline和FilesPipeline自定义使用
爬虫·python·scrapy
木卫二号Coding22 分钟前
Python-文件拷贝+文件重命名+shutil+记录
开发语言·python
爬山算法41 分钟前
Hibernate(44)Hibernate中的fetch join是什么?
前端·python·hibernate
一代明君Kevin学长1 小时前
记录一个上手即用的Spring全局返回值&异常处理框架
java·网络·python·spring
教游泳的程序员1 小时前
【面试问题精选】java开发工程师
python·面试·职场和发展
爬山算法1 小时前
Hibernate(43)Hibernate中的级联删除如何实现?
java·python·hibernate
Stream_Silver1 小时前
【安装与配置Anaconda步骤,包含卸载重装】
python·conda
ai_top_trends1 小时前
AI 生成 PPT 工具横评:效率、质量、稳定性一次说清
人工智能·python·powerpoint