Javascript to HTML converter?

18,509

Solution 1

There's no such thing as a “Javascript to HTML converter”. Javascript is a programming language, not a markup language. Browsers don't convert Javascript to HTML, they execute the Javascript code, and the effect of the Javascript code is to modify the HTML. What you're after is a Javascript interpreter that can process the HTML document.

One way to do this is to use a browser engine behind the scenes. Selenium and Watir (both web application testing engines) are popular choices to call a web browser and drive it with a script — see Are there any good tools besides SeleniumRC that can fetch webpages including content post-painted by JavaScript?.

There are also recent interfaces to Javascript and the DOM in several programming languages such as Jswebkit in Python (example).

Another possibility is to run node.js, which is a standalone JavaScript interpreter (example).

Solution 2

You can try elinks with Javascript support. Once it is build just type:

elinks --dump 1 http://www.example.com/my-js-page.html

and that should do it. Their documentation says that the Javascript support isn't great but this is another way of doing it.

Share:
18,509

Related videos on Youtube

biomorgoth
Author by

biomorgoth

Ubuntu fan since 2010 (was Fedora fan since 2004)

Updated on September 18, 2022

Comments

  • biomorgoth
    biomorgoth over 1 year

    Take for example this snippet of code on a web page.

    <html><body>
    <script language="javascript">
    document.write("The cat");
    document.write(" sat on the mat");
    </script>
    </body></html>
    

    If I were to retrieve this web page via CURL or WGET I would get that text because the Javascript has not been processed.

    But I would like to retrieve this page, so I get the results of the Javascript output. So I would get just..

    The cat sat on the mat
    

    Is there some Linux Javascript sandbox/emulator/pre processor or something of that ilk that would allow me to process that text into html. I understand Javascript is complex and don't expect 100% conversion. But even to get some basic conversion would be helpful.

    I know its possible as I'm sure Google does that when they index web pages to get the best results for the web pages they index.

  • biomorgoth
    biomorgoth almost 11 years
    Thanks, it was difficult to state the question in a form where someone wouldn't try to explain to me the nature of javascript. But my example showed what I meant. The node.js looks promising, will try that out to see how well it does the job of "converting javascript to html" :)