网页爬虫 - Python:爬虫的中文编码问题?
ringa_lee
ringa_lee 2017-04-18 10:26:54
0
4
527

爬取中文网页后正则匹配出中文,得打UTF-8的编码字符

将其输出为.csv文件

在.CSV中显示为乱码

用记事本打开.csv又可以正常显示为中文

有没有大神指点是怎么一回事?怎样才能在Excel里直接看到中文?

ringa_lee
ringa_lee

ringa_lee

reply all(4)
Ty80

The simple way is to use pandasto_excel方法转化成.xlsx文件,因为.xlsxThe default encoding supports Excel by default. The difference is of course that it cannot be opened with Notepad.

import pandas as pd

a = pd.read_csv('./test.csv')

a.to_excel('./test_output.xlsx', index=False)

a.to_excel('./test_output.csv', index=False)

I don’t have windows here to test, you can try to write the encoding as gb2312或者gbk.

For table file I/O, pandas is actually more convenient.

伊谢尔伦

abs1=abs1.decode().encode('gbk')

小葫芦

Excel uses GBK encoding by default.

洪涛

Create a new excel file, then click Data from text to import the csv file

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!