import json
import os
import requests
url = 'https://weibo.com/ajax/statuses/mymblog?uid=3286022555&page={}&feature=0'
headers = {
'referer': 'https://weibo.com/u/3286022555',
'cookie': '........',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54'
}
Flag = True
while Flag:
mun = 1
page = int(input('请输入你要下载图片的页数:'))
response = requests.get(url.format(page), headers=headers).text
data_list = json.loads(response)['data']['list']
os.makedirs('唔猫n/page%d'%page)
name = '唔猫n/page%d'%page
for i in range(20):
pics_id = data_list[i]['pic_ids']
for pic_id in pics_id:
pic = data_list[i]['pic_infos'][pic_id]['mw2000']['url']
img = requests.get(pic, headers=headers).content
with open(f'{name}/{mun}' + '.jpg', 'wb') as f:
f.write(img)
print(f'第{mun}张,下载完成!')
mun += 1
end = input('如果继续下载:输入1, 否则退出:')
if end != '1':
Flag = False
微博图片爬虫
最新推荐文章于 2023-08-16 13:29:25 发布