This is the link to the actual HTML:
doc = Nokogiri::HTML(open('https://www.google.com/finance?q=NYSE%3AAA&fstype=iii'))
And an approximate HTML snippet:
<div id="incannualdiv">
<table id="fs-table">
<tbody>
<tr>..</tr>
...
<tr>
<td>Net Income</td>
<td>100</td>
</tr>
<tr>..</tr>
</tbody>
</table>
</div>
These are the details I'm working with:
doc = Nokogiri::HTML(open('https://www.google.com/finance?q=NYSE%3AAA&fstype=iii'))
div = doc.at "div[@id='incannualdiv']" #div containing the table i want
table = div.at 'table' #table containing tbody i want
tbody = table.at 'tbody' #tbody containing tr's I want
trs = tbody.at 'tr' #SHOULD be all tr's of that table/tbody - but it's only the first TR?
I expect that last bit to give me ALL the <TR>
tags, which would include the <TD>
I'm looking for, but in fact it only gives me the first <TR>
.
Here's the next piece:
irb(main):023:0> a = nil
=> nil
irb(main):024:0> doc.css('#incannualdiv > #fs-table tr').each { |e| if e.text.include? "Net Income\n"; a = e.text; end}
=> 0
irb(main):025:0> a
=> "Net Income\n\n191.00\n611.00\n254.00\n-1,151.00\n"
irb(main):026:0> a.split"\n"
=> ["Net Income", "", "191.00", "611.00", "254.00", "-1,151.00"]