Im trying to make a basic web scraper with Rails. everytime I hit the scrape button it sends me to the correct location but gives me this error everytime.
here is my restaurants_controller.rb
file
def scrape
url = 'https://www.tripadvisor.com/Restaurants-g31892-Rogers_Arkansas.html'
response = RestaurantsScraper.process(url)
if response[:status] == :completed && response[:error].nil?
flash.now[:notice] = "Successfully scraped url"
else
flash.now[:alert] = response[:error]
end
rescue StandardError => e
flash.now[:alert] = "Error: #{e}"
end
Here is my restaurantscrapper.rb
file
class RestaurantsScraper < Kimurai::Base
@name = 'restaurants_scraper'
@engine = :mechanize
def self.process(url)
@start_url = [url]
self.crawl!
end
def parse(response, url, data:{})
response.xpath("//div[@class=_1llCuDZj]").each do |t|
item = {}
item[:title] = t.css('a._15_ydu6b')&.text&.squish&.gsub('[^0-9].', '')
item[:type] = t.css('span._1p0FLy4t')&.text&.squish
item[:reviews] = t.css('span.w726Ki5B').text&.squish
item[:top_reviews] = t.css('a._2uEVo25r _3mPt7dFq').text&.squish
Restaurant.where(item).first_or_create
end
end
end
Here is a picture of the error im getting
Here is the error in the console
Processing by RestaurantsController#scrape as HTML
Parameters: {"authenticity_token"=>"3qXvtTOsU6VVtxaPvNXyCjpdnHLOgCvFgQYzB1JnhoHDz8ySF6gK/n5x+/XW5HC0HwfzQ1bFCu/KCfF3nA1SIQ=="}
I, [2021-01-26 02:35:35 -0600#218] [C: 14760] INFO -- restaurants_scraper: Spider: started: restaurants_scraper
F, [2021-01-26 02:35:35 -0600#218] [C: 14760] FATAL -- restaurants_scraper: Spider: stopped: {:spider_name=>"restaurants_scraper", :status=>:failed, :error=>"#<ArgumentError: wrong number of arguments (given 0, expected 2)>", :environment=>"development", :start_time=>2021-01-26 02:35:35.6330106 -0600, :stop_time=>2021-01-26 02:35:35.6336933 -0600, :running_time=>"0s", :visits=>{:requests=>0, :responses=>0}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
Rendering restaurants/scrape.html.erb within layouts/application
Rendered restaurants/scrape.html.erb within layouts/application (Duration: 0.1ms | Allocations: 41)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 45ms (Views: 41.9ms | ActiveRecord: 0.0ms | Allocations: 4104)
question from:
https://stackoverflow.com/questions/65898150/error-wrong-number-of-arguments-given-0-expected-2 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…