简体   繁体   中英

how to get value of a node in nokogiri

I have this

1.9.3-p286 :073 > doc.css("tr[class~=strong]").children[3].children
 => [#<Nokogiri::XML::Element:0x3fee5e077e98 name="a" attributes=[#
      <Nokogiri::XML::Attr:0x3fee5e077dd0 name="href" 
      value="http://somelink">]>] 

Sample html:

<tr class='strong bf highbeam'>
  <td>December 6th</td>
  <td>Foo</td>
  <td><a href='http://somelink' title='bar'>December 6th 2012 Episode</a></td>
  <td><a href='http://somelink/#disqus_thread'></a></td>
</tr>

How can I fetch the value http://somelink at this point?

不要使用children ,优化CSS选择器,直到获得所需的元素:

doc.at('tr.strong a')[:href]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM