这是我到目前为止写的脚本。我找到的第一个阻止程序是我无法安装MySQLdb包 - 也许我可以使用不同的模块?
import soundcloud
import pandas as pd
from pandas import DataFrame
import MySQLdb
client =
soundcloud.Client(client_id='696b5ca70f5401cc46c9011c78831877')
userId = '110652450'
tracks = client.get('/users/'+userId+'/tracks')
data = []
for x in tracks:
data.append({'Track_Name':x.title,'plays':str(x.playback_count)})
df = pd.DataFrame(data)
database = MySQLdb.connect (host="127.0.0.1",user ="root",passwd="XXX",db="soundcloudstore")
cursor = database.cursor()
query = """INSERT INTO Tracks (Track_Name, Plays) VALUES (%s,%s)"""
for x in df:
Track_Name = df[['Track_Name']].value
Plays = df[['plays']].value
values = (Track_Name, Plays)
cursor.execute(query, values)
cursor.close()
database.commit()
database.close()