import lxml.etree as LX
url= "https://www.w3.org/2003/05/soap-envelope/"
response = requests.get(url)
xml_string = LX.fromstring(response.content)
path='"//*[1.1.1]"'
result = xml_string.xpath(path)
print(result)
上面代码的结果将xpath作为字符串本身返回,并且对于无效的xpath不会出现错误
'"//*[1.1.1]"'
不是XPath。这是一个字符串。请注意报价位置。
仅是字符串的XPath将返回该字符串,这并不令人惊讶。