0

I'd like to re-write a HTML file that references several stylesheets into a new HTML file, where the tags contain only the final, computed styles. This is for further processing of the site where styles such as color need to be known, to avoid having to implement the rather complex logic of style deduction (such as CSS selectors) in that later processing.

Is there some recommended, simple way to do this? I tried saving the file in Chrome and Firefox, but they mostly reproduce the original content, including the CSS file(s). Another option would be to write a program that includes some HTML renderer (such as JavaFX) and manually go through the file, but maybe there is a simpler way.

Eph
  • 225
  • 1
  • 5
  • Does this answer your question? [Chrome Developer Tools : I CSS Coverage unused bytes](https://stackoverflow.com/questions/50166902/chrome-developer-tools-i-css-coverage-unused-bytes) – kmoser Jun 25 '22 at 22:09
  • 1
    If it's like a one off thing, I would use a browser extension like mentioned in [this questions](https://stackoverflow.com/questions/9196451/how-to-export-all-relevant-html-css-for-one-element). When it's for an automation, your could look into `window.getComputedStyle()` [docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle). And write a function to export the page including the actual computed styles. – Lars Jun 25 '22 at 22:24
  • Thanks @Lars, that's both super helpful. I'm going with a Python script that loads the page using Webkit, then uses `window.getComputedStyle()` to get the element's style for further processing. – Eph Jun 29 '22 at 19:17

0 Answers0