使用Scrapy从span类中检索文本

时间:2018-06-18 21:03:37

标签: xpath scrapy web-crawler scrapy-spider

我一直在尝试使用Scrapy从网页中提取文本。这是HTML代码:

<button type="submit" class="inlineBlock _2tga _49ve" title="Like Please" type="submit">
  <div class>
    <span class="_3jn- inlineBlock">...</span>
    <span class="_49vh _2pi7">Like</span>
    <span class="_5n6h _2pih" id="u_0_3">281</span>
  </div>
</button>

编辑

<button class="inlineBlock _2tga _49ve" id="u_0_2" title="Like Please" type="submit">
  <div class>
    <span class="_3jn- inlineBlock">...</span>
    <span class="_49vh _2pi7">Like</span>
    <span class="_5n6h _2pih" id="u_0_3">281</span>
  </div>
</button>

我想提取数字281。为此,我尝试了:

response.xpath("//span[contains(@class,'_5n6h _2pih')]/descendant::text()")

得到了:

[]

也尝试过:

response.xpath("//span[contains(@class,'_5n6h _2pih')]/span[contains(@class, 'u_0_3')]/descendant::text()")

又来了:

[]

0 个答案:

没有答案