Reputation: 41
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
Reputation: 26828
try this one:
https://github.com/geoffyoungs/gtk-webkit-ruby
or phantomjs (but this one is javascript)
Upvotes: 0
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