【发布时间】:2018-11-06 11:36:13
【问题描述】:
尝试从如下所示的元素中提取文本:
<div><strong>"Beginning_of_text"</strong>"Rest_of_text"</div>
当我尝试使用 Scrapy shell 提取 "Rest_of_text" 时
response.css("div::text").extraxt()
它什么也没给我。我是否必须使用一些特殊命令来获取位于元素内 <strong> 标记之后的文本?
【问题讨论】:
-
试试
response.xpath("//div/text()").extract()或response.xpath("//div/strong/following-sibling::text()").extract() -
"Beginning_of_text" : response.css("div strong::text").extract() 也许?
-
尝试使用
response.css("div::text").extract()代替response.css("div::text").extraxt()以获得"Rest_of_text"作为结果。 scrapy中没有.extraxt()这样的东西。
标签: python web-scraping scrapy