How to get urlread to read generated content with Javascript?

25 views (last 30 days)
Hi, I'm trying to have Matlab retrieve the final HTML page with some calculations using Javascript, that is displayed on the body of the page when it's fully loaded. For example, if browsed to this link in the browser: Link with Parameters, 3 lines will show up with some numbers on each line.
However, when I run
result = urlread('http://rampadc.github.io/InstantSim.html?att=0,0,0,0,1770,1242,0,250,0,800,0,0,0&def=1000,1000,0,1000,0,0,1000,0,0,0,0,0,0&wall=20&moral=100&luck=0&attChurch=1&defChurch=1&officer=0')
I get the source code of the page instead of the 3 lines of numbers. Is there any ways I can get urlread() to read the loaded content of the page instead of the source? The simulation code is written fully in Javascript and I don't fully understand it enough to port it to Matlab, so retrieving a page with simulated data is the easiest path for this particular project.
Thank you for your time.

Accepted Answer

Cong Nguyen
Cong Nguyen on 17 May 2015
Thanks for the reply. In the end, I use Node.JS to make a local HTTP server with the JS file in interest to generate dynamic HTTP pages.
Some helpful links:

More Answers (1)

Walter Roberson
Walter Roberson on 17 May 2015
The point of javascript is that it is executed in the user's browser.
Sometimes that javascript code does a bunch of things and then invokes the server to get the answer; in such a case if you tracked far enough and built all of the structures you could invoke the server directly.
But sometimes the javascript code does the entire calculation. In that case, you need to find a way to execute it.
If you are using MS Windows then if you look at the last entry in this post it appears to show a way to create a browser context to run javascript, from which the result could be fetched.

Categories

Find more on Downloads in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!