在mysql中插入python-lis

2024-09-30 04:39:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我曾多次尝试用stackoverflow中的其他问题来解决我的问题,但都没有成功。我现在正在学习python。在

我知道如何用PHP来做,但我需要用python来做。在

我有一个表dentistas,有4列id、web、email、telefono。在

我从另一个文件导入一个包含web url的列表。在

我想在web列中插入这些weburl。在

我现在使用的代码不会在终端中显示错误,但不会向表中插入任何内容:

# coding=utf-8
import MySQLdb
from parser import lista

bd = MySQLdb.connect('localhost', 'testuser', 'test123', 'leads') # Connecting to the database
cursor = bd.cursor()         # Creating the cursor 

for x in lista:
    cursor.execute("INSERT INTO dentistas(web) VALUES(%s)", (x,))

Tags: 文件theimportwebidurlemailstackoverflow

热门问题