Possible Duplicate:
Get link and href text from html doc with Nokogiri & Ruby?
I’m getting the following Nokogiri output:
obj = [#<Nokogiri::XML::Element:0x19b1418 name="a" attributes=[#<Nokogiri::XML::Attr:0x123dd44 name="href" value="http://sample.com">] children=[#<Nokogiri::XML::Element:0x123c408 name="span" attributes=[#<Nokogiri::XML::Attr:0x1201f24 name="class" value="highlight">] children=[#<Nokogiri::XML::Text:0x1143b64 "Web">]>, #<Nokogiri::XML::Text:0x113a9c4 "Sample Text">]>]
How can I get the value "http://sample.com"? I tried obj.attributes("value") but had no luck.
I appreciate any help.
I’m using:
- rails 3.2.x
- nokogiri
You’re almost done:
If there’s only one
<a>tag in the document, you could simplify the code usingat:would return the same value.