码迷,mamicode.com
首页 > 其他好文 > 详细

用接口爬取今日头条图片

时间:2017-05-09 19:40:32      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:text   span   com   time   write   font   tail   request   close   

#encoding:utf8
import requests
import json
import re
demo = requests.get(‘http://www.toutiao.com/api/pc/feed/?category=gallery_detail&utm_source=toutiao&max_behot_time=0&as=A1E5F9D180C2473&cp=5910C214D7E3BE1‘).text
demo1 = json.loads(demo)
n = 0
for i in demo1[‘data‘]:
the_url = ‘http://www.toutiao.com/‘+ i[‘source_url‘]
contents = requests.get(the_url).text
demo = re.compile(‘gallery = {(.*?)}‘,re.S)
list = demo.findall(contents)
for i in list:
n=n+1
print(i)
t = requests.get(i[33:85].replace(‘\/‘,‘/‘)).content
op = open(str(n)+‘.jpg‘,‘wb+‘)
op.write(t)
op.close()

用接口爬取今日头条图片

标签:text   span   com   time   write   font   tail   request   close   

原文地址:http://www.cnblogs.com/lianghongrui/p/6832162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!