I have an HTML document, and I know a value that exists in the document. Using python how would I get the Xpath to that value? (not the value at the Xpath) The value may occur more than once so a list of a way to iterate would be useful.
For example if I want the Xpath to "bytearray":
http://en.wikipedia.org/wiki/Python_(programming_language)
it is (using google Chrome)
//*[@id="mw-content-text"]/table[2]/tbody/tr[3]/td[1]/code
Another example
from lxml import etree
import StringIO
# Example of get value given Xpath (I know how to do this)
f = StringIO.StringIO('<foo><bar>xyz</bar></foo>')
tree = etree.parse(f)
r = tree.xpaths('/foo/bar')
print(r[0].text)
>>> xyz
# Example get Xpath given value. How do I do this ?
value = 'xyz'
path = getXpath(value)
for p in path:
print(p)
>>> /foo/bar
I am not stuck on using Xpath, my purpose is to use some type of location information of the value I know is on a page to retrieve an unknown value on a page with the same layout. I don't what to do it manually because there are hundreds of (value, location) pairs.