xpath匹配嵌套文本

时间:2017-04-05 03:24:35

标签: python-3.x xpath

我想匹配图片中箭头的文字 enter image description here

这是我的代码:

data = sel.xpath('//td[text()="Web Reporter"]/following::*/text()')

但它有虫子,谁能帮助我?

1 个答案:

答案 0 :(得分:0)

尝试以下XPath表达式:

//td[text()="Web Reporter"]/following-sibling::td/normalize-space(text()[1])

..获取"Allen Kong..."

//td[text()="Web Reporter"]/following-sibling::td/normalize-space(text()[2])

...代表"Bounty Tian..."

只需更改text()[N]的索引即可获得所需的文字