Another approach, given that you mention invalid JSON, is to dump a JS object from the JS side via Selemnium's JavascriptExecutor(). I can offer a rough untested sketch only, 1) load the page, 2) wait for a few seconds, 3) tell Selenium driver to execute console.log(JSON.stringify(opportunity));

A similar way is via WWW::Mechanize::PhantomJS. From its doc:

use WWW::Mechanize::PhantomJS; my $mech = WWW::Mechanize::PhantomJS->new(); $mech->get('http://google.com'); # give it some time... $mech->eval_in_page('console.log(JSON.stringify(opportunity));');

Bummer! I have just realised that var opportunity is local to the anonymous function. I guess there is no other way (from the JS side) than injecting a console.log() within the renderer function but I don't know how unless executing JS locally which opens a new can of warms. But if you do find a way with this approach you will not need to parse the DOM. You will have JSON. That's why I leave my comment.

bw, bliako


In reply to Re: Quick 'n dirty extraction of JSON from an HTML page by bliako
in thread Quick 'n dirty extraction of JSON from an HTML page by davebaker

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.