Reputation: 2885
<table>
<tr>
<td>hello</td>
<td><img src="xyz.png" width="100" height="100"></td>
</tr>
</table>
tabledata.rows.each do |row|
row.cells.each do |cell|
puts cell.text
end
end
puts "end"
getting output ->
hello
end
what should i do for output like this ->
hello
xyz.png
end
without using Nokogiri.
Upvotes: 5
Views: 2414
Reputation: 46836
Getting an attribute
You can get the attribute of an element using the Element#attribute_value
method. For example,
element.attribute_value('attribute')
For many standard attributes, you can also do:
element.attribute
Output cell text or image text
Assuming that a cell either has text or an image:
This would look like:
tabledata.rows.each do |row|
row.cells.each do |cell|
if cell.image.exists?
puts cell.image.src #or cell.image.attribute_value('src')
else
puts cell.text
end
end
end
puts "end"
Upvotes: 9