2

I'm not sure what I'm doing wrong. I'm new to coding so it could be something very simple. I've looked around and can't find a solution. It's in the first line in self.scrape_mainpage function.

require 'HTTParty'
require 'Nokogiri'
require 'byebug'
require 'sqlite3'




class Scraper

    attr_accessor :page
    restaurants = []


    def initialize(page="https://www.tripadvisor.com/Restaurants-g31892-Rogers_Arkansas.html")
        @page = page
        url_convert
    end

    def url_convert
        unparsed_page = HTTParty.get(@page)
        @url = Nokogiri::HTML(unparsed_page.body)
    end

    def self.scrape_mainpage
        href = @url.css('_15_ydu6b')[0]["href"].text
        byebug
    end

end
PenoG
  • 35
  • 6
  • Could you show the code you're running? Such as creating the instance of the class etc. Also, you should add your byebug as the first line in the `scrape_mainpage` method so that it will trigger! – Ayudh Dec 05 '20 at 06:52

1 Answers1

1

When you call scrape_mainpage for the first time, the @url variable isn't set yet. You have to organize your code in a way that when scrape_mainpage is called @url is set. Maybe you can turn scrape_mainpage into an instance method, this means not having the self statement before it, then you call it after you initialize an instance of this class.

sidney
  • 1,241
  • 15
  • 32