所以我有一段代码,我需要它来遍历名为vuln_list
的列表,并将循环的每次运行添加到SQLite数据库中。
代码如下:
def product_scan(product_name):
# vulnerability links list
vuln_list = []
# counter for how many vulns per product
count = 0
for entry in d.entries:
if product_name in entry.title:
count += 1
# here we append the hyperlinks, product names and today's date to a list so we can manipulate it later
vuln_list.append(entry.link + entry.title)
for entry in vuln_list:
c.executemany('INSERT INTO nvd_table VALUES (?, ?, CURRENT_DATE)', vuln_list)
当我运行添加的新代码(最后两行)时,出现此错误:
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 109 supplied.
。我不明白的是这个109 supplied
是什么。据我所知,我仅插入链接和标题以及今天的日期,即2 +今天的日期。
我的SQLite表如下:
c.execute('''CREATE TABLE nvd_table (
hyperlink text,
product text,
date_added )''')
任何帮助或指导将不胜感激
答案 0 :(得分:0)
问题是您的vuln_list
只有一维,而在vuln_list.append(entry.link + entry.title)
行中,您将两个字符串合并为一个,即。您的vuln_list包含109个条目(每个条目都包含一个“链接标题”)。
因此,我将建立一个二维列表,然后跳过第二个for循环并使用c.executemany
。或保留它,然后使用c.execute('INSERT...', entry)
,注意:该参数应该是entry而不是完整列表,因为否则所有记录将被插入109次。