Is it possible to get CSS style values in Rvest?

Viewed 140

Is it possible to get color codes and other css styles in Rvest? For example, from Color:Wikipedia there is word Help:Using colors, how can I find the color code '#0b0080' after using rvest::read_html('https://en.wikipedia.org/wiki/Color') ? Looking for something similiare to getCssValue from Selenium.

https://en.wikipedia.org/wiki/Color

1 Answers

‘rvest’ queries static HTML documents. It does not parse or apply CSS information. So no, it cannot tell you the elements’ style information. At best it can tell you if an element has a static style attribute. But most styling isn’t applied this way.

There are other libraries, such as ‘rselenium’, which emulate the evaluation of a website in an actual browser. This is mostly used to crawl dynamically generated web contents, but it should also apply stylesheets, so there may well be a way of retrieving style information using that route.

If there is no direct way for this, at worst you could use ‘rselenium’ to execute the Window.getComputedStyle JavaScript function on your target element.

Related