import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import requests
import json
import pymysql
conn = pymysql.connect(host='localhost',port=3306,user='root',password='root',db='toutiao',charset='utf8')
cursor = conn.cursor()
url = 'http://www.toutiao.com/api/pc/focus/'
wbdata = requests.get(url).text
data = json.loads(wbdata)
news = data['data']['pc_feed_focus']
for n in news:
title = n['title']
img_url = n['image_url']
url = n['media_url']
# print(url,title,img_url)
cursor.execute("INSERT INTO data(title,img_url,url)VALUES('{0}','{1}','{2}');".format(title,img_url,url))
conn.commit()
cursor.close()
conn.close()
print 'ok'
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦