dataabc / weiboSpider

新浪微博爬虫,用python爬取新浪微博数据
8.37k stars 1.98k forks source link

数据无法存入数据库 pymysql.err.DataError:1366 #491

Closed mykaneki closed 1 year ago

mykaneki commented 1 year ago

为了更好的解决问题,请认真回答下面的问题。等到问题解决,请及时关闭本issue。

答:PyPi

答:是

答:是

答:

答:

答: ------------------------------已获取Dear-迪丽热巴(1669879400)的第1页微博------------------------------ 2条微博写入csv文件完毕,保存路径:D:\PycharmProjects\pythonProject1\weibo\Dear-迪丽热巴\1669879400.csv (1366, "Incorrect string value: '\xF0\x9F\xAB\xA3\xE5\x86...' for column 'content' at row 1") Traceback (most recent call last): File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\weibo_spider\writer\mysql_writer.py", line 72, in _mysql_insert cursor.executemany( File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\cursors.py", line 182, in executemany self.rowcount = sum(self.execute(query, arg) for arg in args) File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\cursors.py", line 182, in self.rowcount = sum(self.execute(query, arg) for arg in args) File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\cursors.py", line 148, in execute result = self._query(query) File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\cursors.py", line 310, in _query conn.query(q) File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\connections.py", line 548, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\connections.py", line 775, in _read_query_result result.read() File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\connections.py", line 1156, in read first_packet = self.connection._read_packet() File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\s packet.raise_for_error() File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\protocol.py", line 221, in raise_for_error err.raise_mysql_exception(self._data) File "C:\Users\27951\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pymysql\err.py", line 143, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.DataError: (1366, "Incorrect string value: '\xF0\x9F\xAB\xA3\xE5\x86...' for column 'content' at row 1") 2条微博写入MySQL数据库完毕 Progress: 0%| | 0/152 [00:02<?, ?it/s] 共爬取2条原创微博 信息抓取完毕


======分割线====== 经检查,数据库的编码是utf8mb4 csv、txt文件都可以正常获取并保存,只有数据库不能

dataabc commented 1 year ago

可能是有乱码导致无法保存,如果方便的话,可以通过过滤content乱码或修改数据库编码看看

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

Closing as stale, please reopen if you'd like to work on this further.