Dharmesh Rupani Dharmesh Rupani - 4 years ago 104
Ruby Question

Ruby - unable to write using nokogiri

I am searching a

<div>
element by its classname and want to add it next to other
<div>
element. Following code is not writing data what I get using doc1.search .

require 'nokogiri'

doc1 = Nokogiri::HTML(File.open("overview.html"))
affixButtons = doc1.search('div.margin-0-top-lg.margin-10-bottom-lg.text-center')
doc1.at('div.leftnav-btn').add_next_sibling(affixButtons)


Can someone suggest what I'm missing ?

Answer Source

You're not saving your resulting HTML to file, you can do it like so:

File.open("result.html", "w"){|f| f.write(doc1.to_html)}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download