I build a small script that supposed to find some specific string in a page and return the xpath of the element containing this string. The purpose is to use this xpath for finding string with same context.
I'm using this code:
import requests
from lxml import html
page = requests.get("http://www.w3schools.com/xpath/")
tree = html.fromstring(page.text)
result = tree.xpath('//*[. = "XML"]')
result[0]
returns <Element b at 0x7f034a08e940>
and I can't figure out how to find this element's XPath anyway .
The string I would like to have is:
/html/body/div[4]/div/div[2]/div[2]/div[1]/div/ul/li[2]