使用contains('text', 'some text')
有效,但我想检查它是否只包含我要插入的内容。我发现contains(text()="some text")
,但它作为无效参数返回。你能告诉我有什么问题吗?
lxml.etree.XPathEvalError: Invalid number of arguments
提前致谢。
from requests_html import HTMLSession
session = HTMLSession()
html_source = session.get('any website')
passengers = html_source.html.xpath('*//div//h2[contains(text()="Passengers")]//ancestor::div[contains(@class, "wpb_wrapper")]')[1:-4]
for passenger in passengers:
print(passenger.attrs)