已解决,在python代码是使用pymysql向mysql数据库插入数据时报错pymysql.err.DataError: (1366, '')
问题描述
我从某个网页上抓取并解析了一段html代码,然后将html代码转为utf-8格式,之后将html代码作为数据表的一个属性存入mysql数据库中:
selector = etree.HTML(content_html) content = selector.xpath(news['config']['content']) #找到html中某个节点的html if content: content_html = etree.tostring(content[0], encoding='utf-8').decode('utf-8') content_html = str(content_html,encoding='utf-8') # 保存数据到数据库 sql = "insert into school_news(title,url,content_html,pub_time,school_name,column_name) values(%s,%s,%s,%s,%s,%s)" params = ( title, news['url'], content_html, article_time, news['config']['name'], news['config']['column']) print(params) cursor = db_conn.cursor() cursor.execute(sql, params) db_conn