Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are looking for <a href="http://watir.com/" rel="noreferrer">Watir</a> which runs a real browser and allows you to perform every action you can think of on a web page. There's a similar project called <a href="http://selenium.rubyforge.org/" rel="noreferrer">Selenium</a>.</p> <p>You can even use Watir with a so-called 'headless' browser on a linux machine.</p> <h2>Watir headless example</h2> <p>Suppose we have this HTML:</p> <pre><code>&lt;p id="hello"&gt;Hello from HTML&lt;/p&gt; </code></pre> <p>and this Javascript:</p> <pre><code>document.getElementById('hello').innerHTML = 'Hello from JavaScript'; </code></pre> <p>(Demo: <a href="http://jsbin.com/ivihur" rel="noreferrer">http://jsbin.com/ivihur</a>)</p> <p>and you wanted to get the dynamically inserted text. First, you need a Linux box with <code>xvfb</code> and <code>firefox</code> installed, for example on Ubuntu do:</p> <pre><code>$ apt-get install xvfb firefox </code></pre> <p>You will also need the <code>watir-webdriver</code> and <code>headless</code> gems so go ahead and install them as well:</p> <pre><code>$ gem install watir-webdriver headless </code></pre> <p>Then you can read the dynamic content from the page with something like this:</p> <pre><code>require 'rubygems' require 'watir-webdriver' require 'headless' headless = Headless.new headless.start browser = Watir::Browser.new browser.goto 'http://jsbin.com/ivihur' # our example el = browser.element :css =&gt; '#hello' puts el.text browser.close headless.destroy </code></pre> <p>If everything went right, this will output:</p> <pre><code>Hello from JavaScript </code></pre> <p>I know this runs a browser in the background as well, but it's the easiest solution to your problem i could come up with. It will take quite a while to start the browser, but subsequent requests are quite fast. (Running <code>goto</code> and then fetching the dynamic text above multiple times took about 0.5 sec for each request on my Rackspace Cloud Server).</p> <p>Source: <a href="http://watirwebdriver.com/headless/" rel="noreferrer">http://watirwebdriver.com/headless/</a></p>
 

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