我正在尝试将 YouTube API 中的数据提取到本地 MySQL 表中。我经历了一堆调试,直到我登陆下面的脚本,但我没有从这个脚本中得到任何错误,所以我有点迷茫。任何人有任何建议从哪里开始?
#!/usr/bin/python
# -- coding: utf-8 --
import MySQLdb
import os
import requests
import json
import sys
import re
import requests
import datetime
sql_conn = MySQLdb.connect(host="localhost", user="root", passwd="PSWD", db="researchyoutube")
sql_conn.autocommit(True)
sql_db = sql_conn.cursor(MySQLdb.cursors.DictCursor)
resp = requests.get("https://gdata.youtube.com/feeds/api/videos?q=kitten&orderby=published&start-index=11&max-results=50&v=2&alt=jsonc")
if(resp.status_code == 200):
data = json.loads(resp.content)
for item in data['data']['items']:
title = item['title']
uploaded_on = item['uploaded']
description = item['description']
video_length = item['duration']
user = item['uploader']
video_id = item['id']
video_url = item['player']['default']
sql = "INSERT IGNORE into NCII (title, uploaded_on, description, video_length, user, video_id, video_url) VALUES (title, uploaded_on, description, video_length, user, video_id, video_url)"
sql_db.execute(sql)