Module: Hongkong::News::Scrapers::PhantomScraper

Includes:
Capybara::DSL
Included in:
AppleDailyScraper, MingpaoScraper, OrientalDailyScraper
Defined in:
lib/hongkong/news/scrapers/phantom_scraper.rb

Instance Method Summary collapse

Instance Method Details

#docObject

Get a Nokogiri Document for current page



55
56
57
58
59
60
# File 'lib/hongkong/news/scrapers/phantom_scraper.rb', line 55

def doc
  unless @doc
    @doc = Nokogiri::HTML(html)
  end
  @doc
end

#htmlObject



50
51
52
# File 'lib/hongkong/news/scrapers/phantom_scraper.rb', line 50

def html
  page.html
end

#screenshot_data(filename = 'screenshot.gif') ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hongkong/news/scrapers/phantom_scraper.rb', line 37

def screenshot_data(filename='screenshot.gif')
  data = nil
  file = Tempfile.new(filename)
  begin
    page.save_screenshot(file.path, full: true)
    data = file.read
  ensure
    file.close
    file.unlink
  end
  data
end