nokogiri - refactoring Ruby scraping code -
Actually, I have multiple I have come down to this disturbance, which removes Then you can do this: .main_entry blocks on each page and I get data from each one How can some pieces of this be properly re-implemented? 'Open-yuri' is required 'nautygri' url = #url doc = Nokogiri :: HTML (open (url) doc.css (". Main_entry"). Text = "item_at_css" (".list_artist"). Text title = item.at_css ("list_album"). Text "# {artist} - # {title}" closing
undefined local variable or method 'release' error < / code> error is written more than the methods. Can you explain to me how the code given below is done, why it breaks down and what should I do to decide? Should each
.main_entry block be saved before saving in a cache or an array?
Requires 'Open-Yuri' requires a 'nautguri' class Scraper def initialize (url) @url = url end def release @release || = Doc.css (". Main_entry") || [] End-release text end-defined _method (title:) @title || = Item.at_css (".list_album"). End of text ending personal attr_reader: url def doc @doc || = Nocogiri :: HTML (open (url)) and end scrapper = scrapper.New (# ur) "# {scrapper cartist} - # {scrapar}}" -
is required 'Open-Yuri' is required 'pre-> Nokogiri' class scrap release attr_reader: item def start (item) @item = item end DEF artist @ artist || = Item.at_css (".list_artist"). Text end DEF title @ title || = Item.at_css ("list_album") .text end end class scraper def initialize (url) @url = url end def release @releases || = (Doc.css (". Main_entry") || []). Map {| Item | ScrapedRelease.new (
Scraper.new (url) .releases.each do | release | Puts "# {release.artist} - # {release.ti Tle}" end
Comments
Post a Comment