首页 > 解决方案 > Scraper - 如何保存和存储表情符号

问题描述

我目前在 python 3.x 和 ubuntu 环境下使用来自https://scrapy.org/的 Scraper ,不知何故我想在论坛中获得用户评论,其中包含文本和表情符号。

想知道我们如何将这些表情符号保存到一个数组中,以便我可以在 cvs 或 json 中看到它?

谢谢

标签: pythonweb-scrapingscrapy-spiderscrapescraper

解决方案


如果您至少可以提供页面的 HTML,那就太好了。

如果 emoji 和文本包含在父元素中,假设 div 带有如下注释类。

<div class="comment">
    <div class="description">This is a comment.</div>
    <span>:-)</span>
</div>

那么您可以使用以下 XPath 或 CSS 选择器。

response.css('.comment ::text').extract()

或者

response.xpath('.//div[@class="comment"]//text()').extract()

推荐阅读