python爬虫爬都到的字符串写入mysql错误

for uri in urllist:
        headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36)"}
        response = requests.get(uri,headers=headers).text
        json_str = json.loads(response)
        aa=json_str['data'][0]['result'][0]['additional']
        bb=json_str['data'][0]['result'][0]['ename']
        cc=json_str['data'][0]['result'][0]['kg_pic_url']
        cursor = db.cursor()
        sql = """insert into ady(score,name,PIC) VALUES ('+aa+','+bb+','+cc+')"""
        cursor.execute(sql)
        db.commit()

写入到mysql里面 每一列都是 +aa+ +bb+ +cc+
但是爬到的aa等字符串是可以打印出来的

查看全部
woaiyibao
woaiyibao
2019/04/08 16:26
  • python
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

4个回复