将Unicode转换为等效ASCII码(SCRAPY)

2024-04-19 00:47:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Scrapy从新闻网站抓取文章,并将其添加到mongoDB。但是在插入时,我在MongoDb中得到了这样的unicode字符

"article": "Satya Nadella, Microsoft\u2019s executive vice president of cloud and enterprise, has just been named the company\u2019s next CEO.

我试过了

FEED_EXPORT_ENCODING = "utf-8"

但它只在我运行crawler并将数据导出为JSON文件时起作用,在MongoDB中存储数据时不起作用

在蜘蛛.py文件我写了这行代码来获取文章

item["article"]=response.xpath('//p/text()').getall()

item["article"] =' '.join(item['article'])

如何用ASCII等效字符替换这些字符?你知道吗


Tags: 文件数据网站mongodbarticle文章unicodeitem