It’s not entirely clear what you are trying to do, but this may help:
require 'nokogiri'
html = '<html><head><title>foo</title><body><p>bar</p></body></html>'
doc = Nokogiri::HTML(html)
Using at, you will find the first occurrence of a tag that is reasonable in an HTML document, since you should only have one <body>tag.
doc.at('body') # => #<Nokogiri::XML::Element:0x3ff194d24cd4 name="body" children=[#<Nokogiri::XML::Element:0x3ff194d24acc name="p" children=[#<Nokogiri::XML::Text:0x3ff194d248c4 "bar">]>]>
If you need child elements of a tag, use childrento get them:
doc.at('body').children
If you want to get child nodes as HTML:
doc.at('body').children.to_html
doc.at('body').inner_html
body:
doc.at('body').content
doc.at('body').text
"" attributes <body>:
require 'nokogiri'
html = '<html><head><title>foo</title><body on_load="do_something()"><p>bar</p></body></html>'
doc = Nokogiri::HTML(html)
doc.at('body').attributes # => {"on_load"=>#<Nokogiri::XML::Attr:0x3fdc3d923ca0 name="on_load" value="do_something()">}
doc.at('body')['on_load'] # => "do_something()"
attributes , . Nokogiri:: XML:: Node [], Hash.