I want to extract a specific link from a webpage, searching for it by its text, using Nokogiri:
<div class="links">
<a href='http://example.org/site/1/'>site 1</a>
<a href='http://example.org/site/2/'>site 2</a>
<a href='http://example.org/site/3/'>site 3</a>
</div>
I would like the href of “site 3” and return:
http://example.org/site/3/
Or I would like the href of “site 1” and return:
http://example.org/site/1/
How can I do it?
Original:
Updated:
As far as I know Nokogiri’s XPath implementation doesn’t support regular expressions, for basic
starts withmatching there’s a function calledstarts-withthat you can use like this (links starting with “s”):