用python爬取jk小姐姐照片慢慢看「本地直接下载版」

我这里简单把下载写了下,直接运行代码就能下载,默认主下载目录是 D:bcy ,一个用户图片一个文件夹,也可以自己修改文件主文件夹,没有文件夹会自动创建

只需要安装Python3环境和requests库就能使用,我用的Python版本是3.9

私信小编01即可获取大量Python学习资源

下载效果

代码如下:

import json

import os.path

import time

import requests

url = "https://bcy.net/apiv3/common/circleFeed"

par = {

'circle_id': 492

}

header = {

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62',

'Referer': 'https://bcy.net/tag/492'

}

res = requests.get(url, headers=header, params=par)

res_encode = res.text.encode('utf-8')

res_json = json.loads(res_encode)

for item in res_json['data']['items']:

name = item['item_detail']['uname']

if not os.path.exists(f'D:\bcy\{name}'):

os.makedirs(f'D:\bcy\{name}')

os.chdir(f'D:\bcy\{name}')

else:

os.chdir(f'D:\bcy\{name}')

avatar = item['item_detail']['avatar']

avatar_name = str(avatar).rsplit('.image')[0]

avatar_name1 = str(avatar_name).rsplit('/')[-1]

print(f'{avatar_name1}.jpg')

with open(f'{avatar_name1}.jpg', 'wb') as f1:

f1.write(requests.get(avatar, headers=header).content)

print(name, avatar_name1)

for image in item['item_detail']['image_list']:

images = image['path']

images_name = str(images).rsplit('.image')[0]

images_name1 = str(images_name).rsplit('/')[-1]

with open(f'{images_name1}.jpg', 'wb') as f2:

f2.write(requests.get(images, headers=header).content)

print(f'{images_name1}.jpg')

time.sleep(1)

补充

2022.1.1-11:01

并没有失效,502可能是你下载太快被禁止了,我本地使用没有问题

相关文章

Python中的函数(二) 在上一篇文章中提到了Python中函数的定...
Python中的字符串 可能大多数人在学习C语言的时候,最先接触...
Python 面向对象编程(一) 虽然Python是解释性语言,但是它...
Python面向对象编程(二) 在前面一篇文章中谈到了类的基本定...
Python中的函数(一) 接触过C语言的朋友对函数这个词肯定非...
在windows下如何快速搭建web.py开发框架 用Python进行web开发...