Scrapy没有内置此类功能。html2text是你要寻找的。
这是一个示例spider,它抓取Wikipedia的python页面,使用xpath获取第一段,然后使用以下命令将html转换为纯文本
html2text:
from scrapy.selector import HtmlXPathSelectorfrom scrapy.spider import baseSpiderimport html2textclass WikiSpider(baseSpider): name = "wiki_spider" allowed_domains = ["www.wikipedia.org"] start_urls = ["http://en.wikipedia.org/wiki/Python_(programming_language)"] def parse(self, response): hxs = HtmlXPathSelector(response) sample = hxs.select("//div[@id='mw-content-text']/p[1]").extract()[0] converter = html2text.HTML2Text() converter.ignore_links = True print(converter.handle(sample)) #Python 3 print syntax印刷品:
** Python **是一种广泛使用的通用高级编程语言。[11] [12] [13] 它的设计理念强调代码的可读性,并且其语法允许程序员用更少的代码行来表达概念,而这种语言的表达量比诸如C. [14] [15] 该语言提供了旨在实现小规模和大规模清晰程序的结构。[16]



