0

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 .

unknownbits
  • 2,855
  • 10
  • 41
  • 81
Arihant Godha
  • 2,339
  • 2
  • 26
  • 50

1 Answers1

1

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
Yevgeniy Anfilofyev
  • 4,827
  • 25
  • 27