Note that there are some explanatory texts on larger screens.

plurals
  1. POCapybara, Poltergeist and Phantomjs and giving an empty response in body
    primarykey
    data
    text
    <p>I am getting am empty document back from phantomjs. I am trying to use Capybara and Poltergeist for setting up the phantomjs driver for Capybara. </p> <p>I created a module as follows and included it in the file that uses needs to connect.</p> <pre><code>require 'capybara/poltergeist' module Parser module JSParser include Capybara # Create a new PhantomJS session in Capybara def new_session # Register PhantomJS (aka poltergeist) as the driver to use Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, :debug =&gt; true) end # Use XPath as the default selector for the find method Capybara.default_selector = :xpath Capybara.javascript_driver = :poltergeist Capybara.current_driver = :poltergeist # Start up a new thread @session = Capybara::Session.new(:poltergeist) # Report using a particular user agent @session.driver.headers = { 'User-Agent' =&gt; 'Mozilla/5.0 (Macintosh; Intel Mac OS X)' } # Return the driver's session @session end # Returns the current session's page def html @session.html end end end </code></pre> <p>Then, loading the page as follows:</p> <pre><code>class Loader include Parser::JSParser def load_page new_session visit "http://www.smashingmagazine.com" #let phantomjs take its time sleep 5 puts "html=#{html}" end end </code></pre> <p>Then, finally, calling the load_page</p> <pre><code>Loader.new.load_page </code></pre> <p>Here is the debug response from poltergeist</p> <pre><code>poltergeist [1364758785355] state default -&gt; loading {"response"=&gt;true} {"name"=&gt;"visit", "args"=&gt;["http://www.smashingmagazine.com"]} poltergeist [1364758794574] state loading -&gt; default {"response"=&gt;{"status"=&gt;"success"}} {"name"=&gt;"body", "args"=&gt;[]} {"response"=&gt;"&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;"} </code></pre> <p>As you can see, the response is just a blank document with only the html, head and body tags but nothing in the body tag. </p> <p>What wrong am I doing? Observing network traffic, I am getting the full response back from the host (smashingmagazine.com in this case). Its after the response comes back that I don't know what is happening. Sometimes phantomjs is also crashing and on other occasions, it goes through with the empty body. Here is the last line that is printed on STDERR when phantomjs crashes</p> <pre><code>PhantomJS client died while processing {"name":"visit","args":["http://www.smashingmagazine.com"]} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload