我很想通过 pymssql 将 python 列表写入数据库表。我的目标是将每个列表条目写入同一列的不同行。尝试此操作时出现错误:ValueError: 'params' arg () 只能是元组或字典。有没有办法使用 pymssql 或者我应该使用其他方法?我的代码:from bs4 import BeautifulSoup as bsimport reimport pandas as pdfrom collections.abc import Iterableimport pymssqlconn = pymssql.connect( host='x', port=x, user='x', password='x', database='x')cursor = conn.cursor() cursor.execute('SELECT x FROM x')text = cursor.fetchall()conn.close()raw = [] raw.append(text)raw1 = str(raw)soup = bs(raw1, 'html.parser')autor = soup.get_text()clear = []s = autor.replace('\\n', '')clear.append(s)conn = pymssql.connect( host='x', port=x, user='x', password='x', database='x')cursor = conn.cursor()cursor.execute('INSERT INTO mytablename (columnname) VALUES (?);', [','.join(clear)])conn.close()
添加回答
举报
0/150
提交
取消