python链接Mysql写入数据报Python ‘_elementunicoderesult‘ cannot be converted to a MySQL type错误

有时候爬取页面数据直接用原生sql批量插入数据库会出现以下错误:

Failed processing pyformat-parameters; Python '_elementunicoderesult' cannot be converted to a MySQL type

这是因为通过lxml.etree获取到的字符串可能是_elementunicoderesult,这是Python中字符串的一种,直接把数据格式存入数据库并未将该类型变量转化为SQL对象的方法,因此需要强制转换为str类型,再进行数据保存即可!

猜你喜欢

转载自blog.csdn.net/Lin_Hv/article/details/109737570