Guest User

Untitled

a guest
May 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. require 'rubygems'
  2. require 'nokogiri'
  3.  
  4. html = Nokogiri::HTML(DATA)
  5. html.xpath('//table').each do |htable|
  6. tbody = Nokogiri::XML::Node.new('tbody', html)
  7. htable.children.each do |child|
  8. child.parent = tbody
  9. end
  10. htable.add_child(tbody)
  11. end
  12.  
  13. puts html.xpath('//table').to_s
  14.  
  15. __END__
  16. <table border="0" cellspacing="5" cellpadding="5">
  17. <tr><td>Data</td></tr>
  18. <tr><td>Data2</td></tr>
  19. <tr><td>Data3</td></tr>
  20. </table>
Add Comment
Please, Sign In to add comment