I'm trying to use the nokogiri gem to extract all the urls on the page as well their link text and store the link text and url in a hash.
<html>
<body>
<a href=#foo>Foo</a>
<a href=#bar>Bar </a>
</body>
</html>
I would like to return
{"Foo" => "#foo", "Bar" => "#bar"}
Another way:
And if you're worried that you might have the same text linking to different things then you collect the
href
s in arrays:Here's a one-liner:
Split up a bit to be arguably more readable: