Scrape the DOM of rich JavaScript-enabled applications with ease.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


DEPRECATED: Sunscraper is not actively supported anymore. We are still here to accept pull requests but you better be using another headless scraping solution.

Sunscraper is a gem for prerendering pages with hashbang URLs like!/page.

It works by loading content in the embedded web browser and waiting for a JavaScript method to be called.

HTML = %{
  <script type="text/javascript">
  document.addEventListener("DOMContentLoaded", function() {
    document.getElementById('fuga').textContent =
              ("!skrow tI").split("").reverse().join("");
  }, true);
  <div id='fuga'></div>

Sunscraper.scrape_html(HTML).include?('It works!') # => true

See also documentation.


Sunscraper requires Qt 4.x and QtWebkit packages to be installed on the target system. Sunscraper is not a Ruby C extension; it works by building a Qt shared library and loading it through FFI.

gem install sunscraper

Runtime requirements

On Linux, Sunscraper requires a running X server and a valid DISPLAY environment variable. Consider using Xvfb on a GUI-less production server.


Sunscraper should be compatible across all major implementations on all major operating systems, including Ruby MRI 1.9, JRuby, Rubinius and MacRuby running on GNU/Linux, OS X and Windows.

JRuby versions up to 1.6.5 are known not to work due to a bug in its FFI library.

Ruby MRI 1.8 is not supported because it has a braindead threading model and will never be because I don't care.

Qt 4.7.2 has a race condition in QtWebkit internals which sometimes prevents pages from loading. Use Qt versions not less than 4.7.4 to avoid this bug. As (at this moment) Travis only has Qt 4.7.2, you cannot test Sunscraper-dependent gems on Travis.

However Qt 4.6.3 from Debian stable repositories showed itself working quite well in production mode and can be considered a good choice.

Thread safety

Sunscraper is thread-safe.



It is free software, and may be redistributed under the terms of MIT license.

Bitdeli Badge