Skip to content

Instantly share code, notes, and snippets.

@conorgriffin
Created November 10, 2014 16:13
Show Gist options
  • Save conorgriffin/ec9ca91e7f97b243a1fc to your computer and use it in GitHub Desktop.
Save conorgriffin/ec9ca91e7f97b243a1fc to your computer and use it in GitHub Desktop.
# Explicit path from root of document
elements = doc.xpath("/html"\
"/body"\
"/div[@id='m1']"\
"/div[@class='middle']"\
"/div[@class='col1']"\
"/div[@class='box1l']"\
"/table[@class='cat']"\
"/tr[td/a/img[@src='/i/ple1.gif'] and td/a[contains(@href,'Canon-EF-lenses')]]")
# Selects nodes in the document from the current node that match the selection no matter where they are
elements = doc.xpath("//tr[td/a/img[@src='/i/ple1.gif'] and td/a[contains(@href,'Canon-EF-lenses')]]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment