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:

<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>
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.

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.

Jim Keenan

In reply to Seek Perl equivalent to DOM Inspector by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.