0

I'm writing a program that takes as input the html tag where a piece of information can be found on a web page. I would like to make it as easy as possible to supply this input, ideally copy and pasting from the inspect function of a web browser. In firefox, inspect > copy > css node seemed promising, but it doesn't work when there are multiple sibling tags of the same type anywhere in the path, because it doesn't specify which one you are on.

Is there a good way to get an unambiguous tag identifier directly from a web browser?

pjc
  • 735
  • 1
  • 6
  • 12

1 Answers1

0

The xpath can be used as unambiguous identifier.

With Chrome's developer tools inspect the element and right-click on it in the Elements panel selecting Copy/Copy XPath from the menu (see https://stackoverflow.com/a/42194160/2314737).

For instance the second paragraph in the question has xpath:

var path='//*[@id="question"]/table/tbody/tr[1]/td[2]/div/div[1]/p[2]';

To view it:

document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
user2314737
  • 21,279
  • 16
  • 81
  • 95