cupakob
cupakob

Reputation: 8531

Get/dump/download page after ajax response comes

Here sample code:

require 'nokogiri'
require 'open-uri'

begin
    doc = Nokogiri::HTML(open(url))
rescue
    puts "Fehler ist aufgetretten..."
end

Some parts of the page are loaded asynchronous and i'm missing some values, which are loaded later. Is there any way to open the url, to wait 10 seconds and after that to assign it to the variable doc? Any solutions/ideas with bash/lynx/wget are welcome too :)

Upvotes: 0

Views: 262

Answers (1)

Mark Thomas
Mark Thomas

Reputation: 37517

Unfortunately, waiting 10 seconds isn't going to work, because neither open-uri nor Nokogiri will execute the javascript that loads content asynchronously. You'll need to use a browser driver like Watir or Watir-webdriver. If JRuby is an option, you can use Celerity which is a browser emulator that supports some javascript (using the Watir API), and will likely perform the task you need.

Upvotes: 1

Related Questions