Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Created September 20, 2017 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornerymoose/8e828ad525757ead1b8016d173689441 to your computer and use it in GitHub Desktop.
Save ornerymoose/8e828ad525757ead1b8016d173689441 to your computer and use it in GitHub Desktop.
if i remove rows on localhost:3000 via jquery, those removed rows aren't removed when generating the CSV. Why?
def generate_csv
url = "http://localhost:3000"
doc = Nokogiri::HTML(open(url, :allow_redirections => :safe))
csv = CSV.open("#{Rails.root}/public/collections-output.csv", 'w',{:col_sep => ","})
csv << ['HEADERS HERE']
doc.xpath('//table/tbody/tr').each do |row|
tarray = []
row.xpath('td').each do |cell|
tarray << cell.text
end
csv << tarray
end
csv.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment