I think it would help to split your problem space conceptually between the scraping and the parsing. As far as scraping is concerned, Selenium is a very good tool for automating multiple browsers and testing against them. If all you need is a single browser, look at, say, WWW::Mechanize::Chrome. But do you actually need a browser? If not, LWP is probably all you need. And Dave Cross is the publisher of that book, not the author.

On to the parsing, I have tried a cut down version of your JSON. My code is:

use strict; use warnings; use JSON::PP; use Data::Dumper; my $scrape = <<EOF; <script> $(function () { var opportunity = new US.Opportunity.CandidateOpportunityDetail({"Id":"10eb1d6c-359b +-4f10-84d0-ca2525d88cce","Title":"Relationship Manager","Featured":fa +lse,"FullTime":true,"HoursPerWeek":null,"JobCategoryName":"Qualified +Client Services","Locations":[{"Id":"dd1188b1-18d2-5e8d-9f93-aadbe1a3 +fd22","LocalizedName":"CA-Remote","LocalizedLocationId":null,"Localiz +edDescription":"CA - Remote"}] }); EOF $scrape =~ m/\((\{.*\})\)/gms; my $json = $1; my $ref = decode_json $json; print Dumper $ref;

Does that give you what you need? If not, you may need to specify your problem more clearly.

Regards,

John Davies


In reply to Re: Quick 'n dirty extraction of JSON from an HTML page by davies
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.