V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  canwex  ›  全部回复第 1 页 / 共 1 页
回复总数  1
2019-05-21 21:41:57 +08:00
回复了 onecode 创建的主题 Python 技术渣,谁给写个爬虫,感谢
import requests
import json

url = 'https://adr.meizitu.net/wp-json/wp/v2/posts?page={}&per_page={}'
per_page = 100
page = 52

print('##### spider start #####')
while True:
page += 1
json_data = requests.get(url.format(page, per_page))
data = json.loads(json_data.text)

if not isinstance(data, list):
print('##### spider end #####')
break

for item in data:
thumb_src = item['thumb_src']
title = item['title'] + '.jpg'
print('[+] downloading {} ...'.format(title))
meizi = requests.get(thumb_src)
if meizi.status_code == 200:
with open(title, 'wb') as f:
f.write(meizi.content)
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3457 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 10:47 · PVG 18:47 · LAX 02:47 · JFK 05:47
Developed with CodeLauncher
♥ Do have faith in what you're doing.