I don't necessarily understand why this bit of code is incorrect. I understand the error in that string class doesn't have a method map. But I'm having a hard time wrapping my head around this error.
The error
`<<': undefined method `map' for #<String:0x000001020b8940> (NoMethodError)
The but of code
require 'nokogiri'
require 'open-uri'
require 'csv'
doc = Nokogiri::HTML(open("dent-file.html"))
new_array = doc.search("p").map do |para|
para.text
end
CSV.open("dent.csv", "w") do |csv|
new_array.each do |string|
csv << string
end
end
I want to write each element of the newdoc array to each line of the csv file dent.csv.
CSV#<< accepts an array or a CSV::Row. Convert the string to an array.
csv << [string]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With