Jose
Jose

Reputation: 41

Is there an HTML browser rendering engine for Ruby?

Given a URL, I would like to be able to render the returned HTML to know width and height for each div, fonts' size for each piece of text, color of each element, position of each element on screen, etc.

A possible approach could be traversing the DOM tree with Hpricot and checking CSS style by parsing the associated stylesheet using css_parser gem. But this would not consider default styles, inheritance, floats, etc.

In Java there's Cobra, a Java Web Renderer, which is able to render a web page and query attributes like width, font size, etc. for each fragment. I could use Cobra with JRuby or similar solutions, but prefer a Ruby native tool. Is there any library like this for Ruby?

Upvotes: 4

Views: 933

Answers (3)

Kokizzu
Kokizzu

Reputation: 26828

try this one:

https://github.com/geoffyoungs/gtk-webkit-ruby

or phantomjs (but this one is javascript)

Upvotes: 0

Lie Ryan
Lie Ryan

Reputation: 64837

Selenium does provide an API for querying DOM info, and I believe there's a Ruby binding for Selenium. Its primary strength, which is also its weakness is that it does require a real browser to be present to render the element; this means the data will be accurate with the browser but also that it will be quite heavy.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798576

RbWebKitGTK

Upvotes: 2

Related Questions