python爬虫中遇到的问题以及解决方法

1)运行后报错:“TypeError: cannot use a string pattern on a bytes-like”

原因:content用decode(‘utf-8’)进行解码,由bytes变成string。py3的urlopen返回的不是string是bytes。

解决方案:把’content’类型调整一下:content.decode(‘utf-8’)

2)运行后报错:“sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type”

原因:数据取出来是列表型的,和数据库设计的字段不匹配,需要将数据处理为字符串类型。

解决方案:遍历列表,将列表中的所有元素拼接为一个字符串

原文地址:https://www.cnblogs.com/hyz1900457346/p/12080603.html