花瓣网美女图片爬取

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

查看照片:

相关推荐
weixin_445054723 分钟前
力扣刷题-热题100题-第35题(c++、python)
c++·python·leetcode
_x_w1 小时前
【17】数据结构之图及图的存储篇章
数据结构·python·算法·链表·排序算法·图论
pianmian11 小时前
arcgis几何与游标(1)
开发语言·python
冬天vs不冷1 小时前
SpringBoot条件注解全解析:核心作用与使用场景详解
java·spring boot·python
nanzhuhe2 小时前
python中参数前**的含义
开发语言·python
hello_ejb32 小时前
聊聊Spring AI Alibaba的PdfTablesParser
windows·python·spring
Kairo_012 小时前
秘密任务 2.0:如何利用 WebSockets + DTOs 设计实时操作
python
ghost1432 小时前
Python自学第2天:条件语句,循环语句
开发语言·python·学习
RunsenLIu2 小时前
基于Django实现的图书分析大屏系统项目
后端·python·django
小小福仔2 小时前
Python爬虫第四战(使用防盗链下载视频)
爬虫·python·音视频·反爬·防盗链referer