首页 新闻 会员 周边 捐助

pymysql不插入也不报错?

-2
[已关闭问题] 关闭于 2018-01-23 10:03
`conn = pymysql.connect(host = '127.0.0.1' , port = 3306 , user = 'root' , password = 'root' , db = 'dedao')
cor = conn.cursor()`

`def column():
req = requests.post(url , headers = headers ,data = post_data).text
title = re.findall('''"id":.*?,"title":"(.*?)","''',req,re.S)
config_pic = re.findall('"config":"(.*?)","',req,re.S)
description = re.findall('"intro":"(.*?)",',req,re.S)
price = re.findall(',"price_str":"(.*?)",',req,re.S)
notice = re.findall('"notice":"(.*?)",',req,re.S)
subnum = re.findall(',"subnum":(.*?),"',req,re.S)
price_desc = re.findall(',"price_desc":"(.*?)",',req,re.S)
log_id = re.findall(',"log_id":"(.*?)",',req,re.S)
log_type =re.findall('"log_type":"(.*?)"',req,re.S)
name = re.findall('"name":"(.*?)"',req,re.S)
intro = re.findall('"intro":"(.*?)",',req,re.S)
  for title in title:

sql = '''insert into columns(title) VALUE ('title')'''
   print(title)


for config_pic in config_pic:
print(config_pic)
for description in description:
print(description)
for price in price:
print(price)
for notice in notice:
print(notice)
for subnum in subnum:
print(subnum)
for price_desc in price_desc:
print(price_desc)
for log_id in log_id:
print(log_id)
for log_type in log_type:
print(log_type)
for name in name:
print(name)
for intro in intro:
print(intro)
return title

column()`
--------------------------------------------------------------------------------------------------------
代码如上,我在一个for循环里使用了insert,但是运行之后,表里没有插入新的数据,而且也没报错,请问什么原因呢?
尝试了把插入操作挪到函数的调用环节,就提示title未定义,代码是这样的:
`for title in title:
  column()
   sql = '''insert into columns(title) VALUE ('title')'''`

会发光的主页 会发光 | 菜鸟二级 | 园豆:258
提问于:2018-01-22 11:29

建议给代码加上高亮

dudu 6年前

@dudu: 不太会用Markdown...我重新编辑下

会发光 6年前
< >
分享
所有回答(1)
0

只是文本,没有被执行,更没有错误

today4king | 园豆:3499 (老鸟四级) | 2018-01-22 13:08

for title in title:
  sql = '''insert into columns(title) VALUE (title)'''
  conn.commit(sql)
  print(title)

额,这段加了提交,说是参数少了commit() takes 1 positional argument but 2 were given

支持(0) 反对(0) 会发光 | 园豆:258 (菜鸟二级) | 2018-01-22 13:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册