Python pyodbc插入for循环

时间:2018-01-15 13:09:27

标签: python pyodbc

我试图通过使用库来获取URL并使用extruct json和rdfa数据。不知何故,代码中出现错误并导致sql错误。

代码在

之下
import pyodbc
import requests
from pprint import pprint
import extruct

cnxn = pyodbc.connect('DRIVER={SQL 
Server};SERVER=localhost\SQLEXPRESS;DATABASE=WebCrawler; 
Trusted_Connection=yes')
cursor = cnxn.cursor()
cursor.execute("select Id, url from WebCrawlerEFs")
rows = cursor.fetchall()
for row in rows:
print (row.Id,",", row.url)
r = requests.get(row.url)
data = extruct.extract(r.text, r.url)    
cursor.execute("INSERT INTO RdfaEFs(rdfa) VALUES ('"data"')")     
cnxn.commit() 

1 个答案:

答案 0 :(得分:1)

尝试:

cursor.execute("INSERT INTO RdfaEFs(rdfa) VALUES (?)", (data, ))