Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an identifier (e.g xpath) from a nokogiri object?

Walking through nokogiri and selecting elements with an xpath is fairly easy. I need the vice versa of this, meaning: I need to e.g. call .to_xpath on a nokogiri node to get the full xpath of an element to store it in a record.

Anyone knows a way of doing this?

like image 514
pdu Avatar asked Aug 19 '11 06:08

pdu


1 Answers

Easiest way I can think off would be:

Nokogiri::CSS.xpath_for node.css_path

EDIT: you can give path method a try too.

like image 199
Serabe Avatar answered Nov 15 '22 12:11

Serabe