1 sqlite
我正在抓取网站以获取某些详细信息,然后从那里我想将它们保存在数据库中,以下是上述任务的功能:
def store(title, body):
conn = sqlite3.connect('test2.db')
print("Connection established")
conn.execute("insert into crawled (title, body) values (\"%s\", \"%s\");",(title, body))
conn.commit()
print("Records Created Successfully")
conn.close()
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误:
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 2 supplied
Run Code Online (Sandbox Code Playgroud)
我已经浏览了Stack 中所有可用的解决方案,但没有一个解决方案可以解决我的问题,请有人告诉我我的错误。
问题似乎源于一个小的语法错误。
对于执行命令使用:
conn.execute("insert into crawled (title, body) values (\"%s\", \"%s\");" %(title, body))
Run Code Online (Sandbox Code Playgroud)
注意%开头的%(title, body)和 前面没有逗号。
或者:
conn.execute("insert into crawled (title, body) values (?, ?);",(title, body))
Run Code Online (Sandbox Code Playgroud)
请注意括号前的逗号和?.周围缺少引号。
在sqlite3的文件应具有所需要的所有信息。请注意,它提到最好使用选项二,以避免潜在的 SQL 注入攻击。
| 归档时间: |
|
| 查看次数: |
19514 次 |
| 最近记录: |