Scrapy:如何在此tr中选择下一个td?

时间:2018-07-06 22:07:31

标签: xpath scrapy

我想在td元素中选择tr标签的下一个同级。

tr元素是这样的:

<tr>
  <td>Created On:</td>
  <td>06/28/2018 06:32      </td>
</tr>

我的Scrapy代码如下:response.xpath("//text()[contains(.,'Created On:')]/following-sibling::td")。但这给了我一个空白列表[]

如何选择下一个td

1 个答案:

答案 0 :(得分:2)

尝试以下XPath表达式:

//text()[contains(.,'Created On:')]/../following-sibling::td

您试图从错误的上下文节点使用following-sibling轴。返回上一级即可解决此问题。

另一种方法是首先匹配td元素,如该表达式所示:

//td[contains(text(),'Created On:')]/following-sibling::td
相关问题