Python: xpath 仅查找包含确切单词的

Python: xpath find the that contains the exact word only

我想获取总资产数据,但 return 包含总资产的所有数据。 如何只获取总资产的数据

from lxml import html
import requests

page_inv_n = requests.get('http://quotes.wsj.com/MY/XKLS/HEIM/financials/annual/balance-sheet')
inv_n = html.fromstring(page_inv_n.content)
Assets = inv_n.xpath(''//td[contains(.,"Total Assets")]/following-sibling::td/text()')[0]

正确的输出是 813,655.0 而不是 0.50%,它来自 Cash & ST Investments / Total Assets,也包含 Total Assets。

请指教

您可以通过精确的文本内容来匹配节点,如下所示:

//td[text()="Total Assets"]/following-sibling::td/text()

//td[.="Total Assets"]/following-sibling::td/text()

在这种情况下,两者应该以相同的方式工作