I am trying to write program in PHP, which would download and parse html source. Problem is, when I try to download html, which is generated by js.
Is there any chance to download the file after function onload() is completed?
Thanks
I am trying to write program in PHP, which would download and parse html source. Problem is, when I try to download html, which is generated by js.
Is there any chance to download the file after function onload() is completed?
Thanks
Not a trivial task as Javascript is actual active code that has to be interpreted by the browser. What you get from the server is the actual HTML, and all the things that javascript does is on the client side and is completely out of the hands of the server who is giving you the Web page. You can't solve this in general with static analysis (ie guessing what will happen by looking at the code without actually executing it). The only way to reliably do this is to actually execute the javascript.
That being said, you probably don't want to write your own javascript interpreter from scratch. There are "headless" implementations out there that have a javascript interpreter just like a browser does but doesn't display it on a screen - it does all the operations on a virtual DOM. Try looking into PhantomJS.
EDIT See this question where someone basically does what you are asking.I think it should work as-is for your case.
I don't know of any "pure" php solutions, but you could easily automate running the script with php. If you need to stay PHP due to any reason then "headless DOM renderer" is what I would search for.