我试图通过使用库来获取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()
答案 0 :(得分:1)
尝试:
cursor.execute("INSERT INTO RdfaEFs(rdfa) VALUES (?)", (data, ))