Search code examples
rubymechanizemechanize-ruby

Use of URI method in mechanize#link


I am trying to get an URL from an available a tag. So If my html contains

<a class= "classname" href="someurl.com"; title="title">some text</a>

If I do something like this

@url = link.search("a[@href]")

It returns me the above html.

If I do .text then it returns me Some text.

But I want to get the href url. I have seen this link. but not getting how to implement it.

Any suggestions .


Solution

  • I think mechanize uses nokogiri to parse content. So, to get attribute's value you could use attr method and then get it's value, something like this:

    link.search("a[@href]").attr('href').value