Class: BandcampDiscover::Scrapers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bandcamp-discover/scrapers/base.rb

Direct Known Subclasses

Album, Label, Music

Instance Method Summary collapse

Constructor Details

#initialize(url:, browser:, max_tasks: 2) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/bandcamp-discover/scrapers/base.rb', line 10

def initialize(url:, browser:, max_tasks: 2)
  @url = url
  @browser = browser
  @page = browser.new_page
  @max_tasks = max_tasks
end

Instance Method Details

#scrape(force: false) ⇒ Object



17
18
19
20
21
# File 'lib/bandcamp-discover/scrapers/base.rb', line 17

def scrape(force: false)
  yield @page if block_given?
rescue Playwright::TimeoutError => e
  raise ScrapeError, "Timed out waiting for an element on #{@url}: #{e.message}"
end