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'
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。