2012-12-07 45 views
0

節點的值,我有這個如何讓引入nokogiri

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">]>] 

樣本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> 

我怎樣才能獲取該點的值http://somelink

+0

如果你表現出了HTML的樣本,而不是IRB步驟的輸出它確實有幫助。 –

回答

3

不要使用children,直到你得到你想要的元素提煉你的CSS選擇器:

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