John
John

Reputation: 634

Get page-source by using Rails with poltergeist

How to setup Rails with poltergeist and poltergeist to get the page-source for a specific page. Similar with what the code below does.

require 'selenium-webdriver'
require 'nokogiri'

driver = Selenium::WebDriver.for :firefox
driver.get "http://www.google.com/"

doc = Nokogiri::HTML(driver.page_source)

Or other setup, but the point is not to open a browser, and no interaction are required, just the rendering of javascript.

Upvotes: 1

Views: 463

Answers (1)

phoet
phoet

Reputation: 18845

Poltergeist ist meant to be used with Capybara.

This is how you can use Capybara with a remote server: https://github.com/jnicklas/capybara#calling-remote-servers

This is a working snippet:

require 'capybara'
require 'capybara/poltergeist'

Capybara.current_driver = :poltergeist
Capybara.app_host = 'http://www.google.com'
Capybara.visit('/')
puts Capybara.page.body

Upvotes: 3

Related Questions