import json
import pymysql
coon=pymysql.connect(host="192.168.67.41",port=3306,user="root",password="123456",db="weibo");
cursor=coon.cursor();
with open("data.txt","r",encoding="utf-8") as file:
dates=file.readlines();
for item in dates:
t = json.loads(item);
effect=cursor.execute(
"insert into weibo_info(id,created_at,content,source,reports_count,comments_count,attitudes_count) values (%s,%s,%s,%s,%s,%s,%s)"
,(t["id"],t["created_at"],t["content"],t["source"],
t["reports_count"],t["comments_count"],t["attitudes_count"]));
print(effect);
coon.commit();
cursor.close();
coon.close();
将json多行数据传入到mysql中使用python实现(简化版)
最新推荐文章于 2024-05-17 10:15:39 发布