My problem is that I can't get to the second row in this table
It only prints out the text from the td's on the first tr.
<table class="admintabletext" width="99%;" cellspacing="2"
cellpadding="4">
<tr>
<td class="admintabletitletext2">Namn</td>
<td class="admintabletitletext2">Telefon</td>
<td class="admintabletitletext2">Mobil</td>
<td class="admintabletitletext2"> &l开发者_如何学编程t;/td>
</tr>
<tr bgcolor="#eeeeee">
<td valign="top">name<br>address</td>
<td valign="top">mobile</td>
<td valign="top"><strong>number</strong><br>
</td>
<td valign="top"><a href="#" onclick="return copyValues(0);">Kopiera</a></td>
</tr>
</table>
My code looks something like this:
doc = Nokogiri::HTML(open(url), nil, 'UTF-8')
doc.xpath( '//table/tr/td//text()' ).each_with_index do |td, index|
# DO stuff with td
end
There is problem not in your code. Your code works fine for me.
doc.xpath( '//table/tr/td//text()' ).each_with_index do |td, index|
puts "#{index}. #{td.content}"
end
# 0. Namn
# 1. Telefon
# 2. Mobil
# 3.
# 4. name
# 5. address
# 6. mobile
# 7. number
# 8. Kopiera
精彩评论