I am trying to take a screenshot of all the div.auto_items on all the subpages on this website Link one by one.
What I am trying to achieve is to have all vehicles as a picture and then display them on a kiosk machine as an image slideshow. It should run from cron because the vehicles change from time to time (naturally)
What I have so far is this:
#!/root/.rbenv/shims/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'screencap'
base_url = "http://vacs.opelduna.hu.opel.carusseldwt.com/result/"
page = Nokogiri::HTML(open(base_url))
page.encoding = 'utf-8'
page.css('div#rk div.index_top div.small_search_results_pager ul li.paging_item a span').each do |el|
#puts el.text
count = 0
page2_url = "http://vacs.opelduna.hu.opel.carusseldwt.com/result/" + el.text
#page2 = Nokogiri::HTML(open(page2_url))
f = Screencap::Fetcher.new(page2_url)
#page2.css('div#rk div.auto_item').each do |car2pic|
count = count+1
#f = Screencap::Fetcher.new(car2pic)
screenshot = f.fetch(
:output => '~/car2pic_'+count.to_s+'.png', # don't forget the extension!
# optional:
:div => '.auto_content', # selector for a specific element to take screenshot of
#:width => 1024,
#:height => 768,
#:top => 0, :left => 0, :width => 100, :height => 100 # dimensions for a specific area
)
#end
end
But this does not seem to do anything. Or at least I have left it "running" for 10 minutes, and no pictures were saved :( It is important that this machine is headless, so no desktop.
I read it here how to screenshot a div using phantomJS that one solution is to render the page partially, and then take a screenshot, but I thought that this: https://github.com/maxwell/screencap takes care of that.
thanks tom