Tool to generate Xpath

Asked

Viewed 1,398 times

3

Hello, I’m making a Spider to capture with Xpath some web data.

But the creation of xpath is a bit laborious. Does anyone know any way to train Xpath? Example; I click 5 times on a link and some tool generates xpath.

Any hint is welcome.

Thank you!

4 answers

4


I compiled the answers found here:

https://stackoverflow.com/questions/3030487/is-there-a-way-to-get-the-xpath-in-google-chrome

"Chrome Dev Tools"

When using "Chrome Dev Tools" (You can right-click on any element and ask to "inspect element") you can right-click on the element, then "Copy Xpath".

Add-on for Chrome.

https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl

Javascript console

You can also use $x in the Chrome javascript console.

ex: $x("//img")

Xpather

I didn’t get to test, but this tool apparently seems to be what you want.

Xpather

  • The idea of Xpather seems to be what I need.. but I couldn’t install in Firefox

  • 1

    Nice build, Arthur, +1! I’ve used this add-on for Chrome a lot. I added a reply with http://selectorgadget.com -- take a look if you don’t know, it’s pretty cool. ;)

3

Try the bookmarklet Selectorgadget.

It works like this: right after you fire, you click on something you want to capture. It generates a very generic selector, and highlights in yellow the captured sections.

From there on, you can refine the selection with: 1) by clicking on a highlighted area to remove from the selection; or 2) by clicking on an unassigned area to add the selection.

By default it generates a CSS selector, but has an Xpath button to pick up the equivalent expression in Xpath.

1

Has a add-on for Firefox that queries XPath on a page, called XPath Checker.

Add-on page

0

Install xmllint (tiny tool, usually already installed on linux) and it’s time to practice xpath:

xmllint --xpath '//symbol' file.xml

or, in the case of html:

xmllint --html --xpath '//table' file.html

or even

xmllint --html  --xpath '//a' 'http://a.b.c/index.html' > links.txt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.