我从站点中抓取一个元素列表,并从中提取两个值。text
和href
。我不知道如何将它们添加到循环中的mysql
DB中。我在循环中尝试了execute
,没有使用它们所对应的列表,但失败了。因此,我尝试了executemany
,但我认为我的格式可能不正确。我看到了一些例子,其中元组列表被馈送到executemany
,我不知道在这种情况下如何做
for name in name_eles:
names_list.append(name.text)
n_li = name.get_attribute('href')
names_links.append(n_li)
sql = "INSERT INTO profiles(company, coprofile) VALUES (%s,%s)"
val = [(name for name in name_list),(n_li for n_li in names_links)]
cursor.executemany(sql,val)
这就是我得到的错误
MySQLdb._exceptions.ProgrammingError: not all arguments converted during bytes formatting
必须在
executemany
参数中传递list
个tuples
您可以简单地尝试以下方法:
您可以阅读更多关于它的信息here
相关问题 更多 >
编程相关推荐