jkeenan1 has asked for the wisdom of the Perl Monks concerning the following question:
Short version:
Is there a Perl technique or a CPAN distribution which would enable me to capture the DOM of some executed HTML in the way that Safari Inspector or Firefox Web Inspector does?
Full version:
We need to be able to identify the file type for every file we receive from upstream servers and push to a downstream server. Simply looking at the file's extension works in the overwhelming majority of cases: .gif, .jpg, .swf, .png, etc. However recently we have a case where the HTML we are supplied from upstream contains URLs which, rather than directly pointing to "img" with extensions, point to a site where JavaScript is executed and where, ultimately, a Flash file is displayed. Our current code can't see what that JavaScript does and, consequently, fails to correctly identify a file as an ".swf" to our downstream recipients.
Pseudo-code:
Should this HTML ultimately be displayed on a browser that does not support scripting, the .gif will be displayed. But in all other cases the JS inside the <script> tag is executed and, ultimately, a Flash file is displayed.<html><head></head> <body> <script> Big hunk of Javascript with URLs not ending in a file extension </script> <noscript> <img src="http://path/to/image.gif></img> </noscript> </body> </html>
I have tried using LWP::UserAgent to make the call. The call succeeds, but the HTTP::Response object simply contains the URL in the original call. However, when I execute this in a browser with developer tools, I get better results. In either Safari's Inspector or Firefox's Web Inspector, I can see what in Safari, at least, is labelled the DOM view of the result. More pseudo-code:
<html><head></head> <body> <script> Big hunk of Javascript with URLs not ending in a file extension <div> <object> Hunk of code including URL ending in ".swf" and "type" clearly indicat +ing shockwave flash file. </object> </div> </script> <noscript> <img src="http://path/to/image.gif></img> </noscript> </body> </html>
I want to capture this DOM view and parse it so that I can accurately identify the Flash file to the downstream server. If Safari and Firefox (and probably other browsers as well) can do this, my hunch is that Perl can do it as well. But I'm not primarily a web developer, so I turn to you.
Thank you very much.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Seek Perl equivalent to DOM Inspector (js pipe dream)
by Anonymous Monk on Sep 28, 2013 at 22:58 UTC | |
by Anonymous Monk on Sep 28, 2013 at 23:07 UTC | |
Re: Seek Perl equivalent to DOM Inspector
by jkeenan1 (Deacon) on Oct 01, 2013 at 16:54 UTC | |
by Anonymous Monk on Oct 02, 2013 at 07:22 UTC |