Is there an HTML browser rendering engine for Ruby?

Given the URL, I would like to let the returned HTML know the width and height for each div, the font size for each piece of text, the color of each element, the position of each element on the screen, etc.

A possible approach would be to move the DOM tree using Hpricot and check the CSS style by parsing the related stylesheet using the css_parser gem. But this will not take into account default styles, inheritance, floats, etc.

Java has Cobra, the Java Web Renderer, which is capable of displaying a web page and request attributes such as width, font size, etc. for each fragment. I could use Cobra with JRuby or similar solutions, but I prefer the Ruby hand tool. Is there such a library for Ruby?

+4
source share
3 answers

Selenium provides an API for querying DOM information, and I believe there is a Ruby binding for Selenium. Its main strength, which is also its weakness, is that a real browser requires a real browser; this means that the data will be accurate with the browser, but will also be quite heavy.

+1
source

try the following:

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

or phantomjs (but this is javascript)

0
source

Source: https://habr.com/ru/post/1299541/


All Articles