require ''rubygems'' require ''nokogiri'' require ''sqlite3'' FIELD_NAMES = [[''selectcity'', ''VARCHAR''],[''match'', ''VARCHAR''], [''phone_no'', ''NUMERIC''], [''name'', ''VARCHAR''],[''address'', ''VARCHAR''] ] TABLE_DIV_ID = "#dgrSearch" OFILE = File.open(''data-hold/tel-directory.txt'', ''w'') OFILE.puts( FIELD_NAMES.map{|f| f[0]}.join("\t") ) DBNAME = "data-hold/tel-directory.sqlite" File.delete(DBNAME) if File.exists?DBNAME DB = SQLite3::Database.new( DBNAME ) TABLE_NAME = "telephone_records" DB_INSERT_STATEMENT = "INSERT into #{TABLE_NAME} values (#{FIELD_NAMES.map{''?''}.join('','')})" DB.execute "CREATE TABLE #{TABLE_NAME}(#{FIELD_NAMES.map{|f| "`#{f[0]}` #{f[1]}"}.join('', '')});" FIELD_NAMES.each do |fn| DB.execute "CREATE INDEX #{fn[2]} ON #{TABLE_NAME}(#{fn[0]})" unless fn[2].nil? end Dir.glob("data-hold/pages/*.html").reject{|f| f =~ /All match/}.each do |fname| meta_info = File.basename(fname, ''.html'').split(''--'') page = Nokogiri::HTML(open(fname)) page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| data_tds = tr.css(''td'').map{ |td| td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '' '').strip } data_row = meta_info + data_tds OFILE.puts( data_row.join("\t")) DB.execute(DB_INSERT_STATEMENT, data_row) end end OFILE.close -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 May 2012 16:46, Prajwal B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> require ''rubygems'' > require ''nokogiri'' > require ''sqlite3'' > > FIELD_NAMES = [[''selectcity'', ''VARCHAR''],[''match'', ''VARCHAR''], > [''phone_no'', ''NUMERIC''], [''name'', ''VARCHAR''],[''address'', ''VARCHAR''] ] > > TABLE_DIV_ID = "#dgrSearch" > OFILE = File.open(''data-hold/tel-directory.txt'', ''w'') > OFILE.puts( FIELD_NAMES.map{|f| f[0]}.join("\t") ) > > DBNAME = "data-hold/tel-directory.sqlite" > File.delete(DBNAME) if File.exists?DBNAME > DB = SQLite3::Database.new( DBNAME ) > > TABLE_NAME = "telephone_records" > DB_INSERT_STATEMENT = "INSERT into #{TABLE_NAME} values > (#{FIELD_NAMES.map{''?''}.join('','')})" > > DB.execute "CREATE TABLE #{TABLE_NAME}(#{FIELD_NAMES.map{|f| "`#{f[0]}` > #{f[1]}"}.join('', '')});" > FIELD_NAMES.each do |fn| > DB.execute "CREATE INDEX #{fn[2]} ON #{TABLE_NAME}(#{fn[0]})" unless > fn[2].nil? > end > > Dir.glob("data-hold/pages/*.html").reject{|f| f =~ /All match/}.each do > |fname| > meta_info = File.basename(fname, ''.html'').split(''--'') > page = Nokogiri::HTML(open(fname)) > > page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| > data_tds = tr.css(''td'').map{ |td| > td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '' '').strip > } > > data_row = meta_info + data_tds > OFILE.puts( data_row.join("\t")) > DB.execute(DB_INSERT_STATEMENT, data_row) > > end > end > > OFILE.closeIt might be easier to help if you told us what the error is, and which line is causing the problem. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Cut it down to the minimun necessary to show the problem. There are several each calls here. Jeffrey Quoting Prajwal B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> require ''rubygems'' > require ''nokogiri'' > require ''sqlite3'' > > FIELD_NAMES = [[''selectcity'', ''VARCHAR''],[''match'', ''VARCHAR''], > [''phone_no'', ''NUMERIC''], [''name'', ''VARCHAR''],[''address'', ''VARCHAR''] ] > > TABLE_DIV_ID = "#dgrSearch" > OFILE = File.open(''data-hold/tel-directory.txt'', ''w'') > OFILE.puts( FIELD_NAMES.map{|f| f[0]}.join("\t") ) > > DBNAME = "data-hold/tel-directory.sqlite" > File.delete(DBNAME) if File.exists?DBNAME > DB = SQLite3::Database.new( DBNAME ) > > TABLE_NAME = "telephone_records" > DB_INSERT_STATEMENT = "INSERT into #{TABLE_NAME} values > (#{FIELD_NAMES.map{''?''}.join('','')})" > > DB.execute "CREATE TABLE #{TABLE_NAME}(#{FIELD_NAMES.map{|f| "`#{f[0]}` > #{f[1]}"}.join('', '')});" > FIELD_NAMES.each do |fn| > DB.execute "CREATE INDEX #{fn[2]} ON #{TABLE_NAME}(#{fn[0]})" unless > fn[2].nil? > end > > Dir.glob("data-hold/pages/*.html").reject{|f| f =~ /All match/}.each do > |fname| > meta_info = File.basename(fname, ''.html'').split(''--'') > page = Nokogiri::HTML(open(fname)) > > page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| > data_tds = tr.css(''td'').map{ |td| > td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '' '').strip > } > > data_row = meta_info + data_tds > OFILE.puts( data_row.join("\t")) > DB.execute(DB_INSERT_STATEMENT, data_row) > > end > end > > OFILE.close > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
no method error "each" for nil class page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| data_tds = tr.css(''td'').map{ |td| td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '' '').strip } -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| data_tds = tr.css(''td'').map{ |td| td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '' '').strip } first line is saying no method error ''each'' do for nil class -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 May 2012 18:50, Prajwal B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| > data_tds = tr.css(''td'').map{ |td| > td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '' '').strip > } > > first line is saying no method error ''each'' do > for nil classThen page.css("#{TABLE_DIV_ID} tr")[1..-2] is nil Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dir.glob("data-hold/pages/*.html").each do |fname| meta_info = File.basename(fname, ''.html'').split(''--'') page = Nokogiri::HTML(open(fname)) page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| data_tds = tr.css(td).map{ |td| td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '''').strip } error in each do method in first line of both blocks block irb binding in second block first line -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 27 May 2012 06:31, Prajwal B. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dir.glob("data-hold/pages/*.html").each do |fname| > meta_info = File.basename(fname, ''.html'').split(''--'') > page = Nokogiri::HTML(open(fname)) > > page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| > data_tds = tr.css(td).map{ |td| > td.text.gsub(/[$,](?=\d)/, '''').gsub(/\302\240|\s/, '''').strip > } > > error in each do method in first line of both blocksWhy have you posted this again rather than continuing with previous thread? As I said previously the object you are calling .each on must be nil. Have a look at the Rails Guide on Debugging for suggestions as to how to debug the code to find out why. Colin> > block irb binding in second block first line > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.