我想用从网站检索到的一些信息更新MySQL表中的一列。该列的名称为“names”,表的名称为“HuntsPointYelp”
我的更新查询出现编程错误,我认为这是一个语法错误
谢谢
import pymysql
conn = pymysql.connect(host='127.0.0.1',
unix_socket='/tmp/mysql.sock',user='root',
passwd=' ', db='mysql', charset='utf8')
cur = conn.cursor()
cur.execute('USE HuntsPointsBusinesses')
def storeNames (names):
cur.execute('UPDATE HuntsPointYelp SET = ("%s")', names)
cur.connection.commit()
def getNames (bs):
#names:
restGrid = bs.find_all ("ul", {"class": "lemon--ul__373c0__1_cxs
undefined list__373c0__2G8oH"})
#namesList = []
time.sleep(2)
for i in restGrid:
h3 = i.find_all ("h3")
for h in h3:
target = h.find_all ("a")
for t in target:
if "name" in t.attrs:
if t.attrs is not None:
names = t["name"]
storeNames (names)
driver.get ("https://www.yelp.com/search?
cflt=restaurants&find_loc=Hunts+Point%2C+Bronx%2C+NY+10474")
pageSource = driver.page_source
bs = BeautifulSoup (pageSource, "html.parser")
names = getNames(bs)
ProgrammingError: (1064, 'You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for
the right syntax to use near \'= ("\'Roaming Woodfired Pizza\'")\'
at line 1')
你有两个问题
首先,您缺少要设置的列的名称。第二,你不应该把占位符放在引号里
cur.execute()
为您执行必要的引号,因此您最终会在值中使用文字引号相关问题 更多 >
编程相关推荐