0

I'm looking for a way to render an HTML, and get the whole document source of if after a browser (let's say firefox), renders it... The thing is that I'm using some numbering, just the looks, such as CSS ::before or javascript to highlight code blocks, or render Mathjax.

My question is, if there is a way to do a "server render" to do that? If so how?

ekiim
  • 792
  • 1
  • 11
  • 25
  • 1
    It sounds like you're looking for a headless browser. – SLaks Jul 05 '18 at 22:35
  • I have never heard about that but sounds like exactly what I need. – ekiim Jul 05 '18 at 22:36
  • http://phantomjs.org/ but it seems the project is suspended – geekley Jul 05 '18 at 22:36
  • https://www.keycdn.com/blog/headless-browsers/ read that – mlegg Jul 05 '18 at 22:38
  • https://stackoverflow.com/a/814929/9638388 – geekley Jul 05 '18 at 22:38
  • I hope I knew the term before, or even that that was a thing, thanks, this was so useful I got super excited about all the problemes this solves. – ekiim Jul 05 '18 at 22:39
  • jsdom is another option: https://www.npmjs.com/package/jsdom – joknawe Jul 05 '18 at 22:41
  • 1
    Phanthomjs is superceded by Chrome Headless. Have a look at puppeteer for instance which is a library to easily control Chrome Headless from node.js – Geert-Jan Jul 05 '18 at 23:22
  • I have a question on how to choose one, I just want to run the CSS so I can use counter and enumerate, putting prefixes, render Katex (something like mathjax), and code highlighting. Should I open a new question or could some one directly to the simplest one, I'm alrady working with python, to do it, but I don't mind moving to node in case of that... – ekiim Jul 06 '18 at 06:29

1 Answers1

0

Using a webdriver like selenium, just open the file or URI, that you are amming to render, and get the source of the page, after it renders.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(URI)
source = driver.page_source
ekiim
  • 792
  • 1
  • 11
  • 25