【发布时间】:2017-05-11 07:54:34
【问题描述】:
我认为我使用 Scrapy 错误,但我正在尝试使用 xpath 从页面上的 H2 中仅选择文本并去除内部标签。
例如。
<h2>Welcome to my <a href="#">page</a></h2>
<h2>Welcome to my Page</h2>
我尝试过使用//h2//text(),但它会生成这样的数组
item["h2s"] = response.xpath('//h2//text()').extract()
['Welcome to my',
'page',
'Welcome to my Page']
我尝试了多种组合,但似乎无法得到我想要的数组
['Welcome to my page',
'Welcome to my Page']
【问题讨论】: