1 #coding=utf-8 
 2 
 3 import json
 4 import pymysql
 5 
 6 db = pymysql.connect("localhost","root","asdfg48520.","test",use_unicode=True, charset="utf8")
 7 cursor = db.cursor()
 8 sql = """ DROP TABLE  IF EXISTS SHUJU1 """
 9 cursor.execute(sql)
10 
11 sql = """CREATE TABLE SHUJU1 (
12          TITLE  VARCHAR(20) NOT NULL,
13          TIME  VARCHAR(200),
14          TEXTT VARCHAR(200),
15          URL VARCHAR(200) )"""
16 cursor.execute(sql)
17 db.commit()     
18 data = []
19 
20 with open(r'C:/Users/18341/temp/shixi/10.21/pc1.json') as f:
21     for line in f:
22         data.append(json.loads(line))
23 
24 for item in data:
25     sql="""INSERT INTO SHUJU1 (TITLE,TIME,TEXTT,URL)VALUES(%s,%s,%s,%s)"""
26     cursor.execute(sql,(item['time'],item['url'],item['title'],item['text']))
27 
28 db.commit()
29 db.close()

 

相关文章:

  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-11-27
  • 2021-08-01
  • 2019-09-08
猜你喜欢
  • 2022-01-24
  • 2021-08-03
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
相关资源
相似解决方案