0

Trying to decode lots of information which is returned to be from a server.

Effectively I'm just printing out returned data, the data itself is correct, except I'm getting '\u003c' instead of '<', etc... I'm trying to convert all these to the actual characters!

edit:

code:

$url = "http://people.gaa.ie/club/fixResult.jsp?callback=?&clubID=1329&compID=6785&leagueTable=N&colour=1E58AC";
$content = get($url);

print $content;

output snippet is:

parseJSON({"content":"\u003cdiv id\u003d\"fixtures\"\u003e\n\u003cdiv class\u003d\"aFixture\" style\u003d\"display:none;\"\u003e\n\t\u003ch5 class\u003d\"primaryColor\"\u003eSenior Football Championship Group Two\t\u003c/h5\u003e\n\t\u003ch5 class\u003d\"primaryColor\"\u003e20.04.12 (Fri)\u003c/h5\u003e\n\t\u003cul class\u003d\"fixtures_list\"\u003e\n\t\t\u003cli\u003e\n\t\t\t\u003cp style\u003d\"font-weight:bold;\"\u003e\n\t\t\t\tRound 1\n\t\t\t\u003c/p\u003e\n\t\t\t\u003cp\u003e\n\t\t\t\t\u003cspan class\u003d\"teams\"\u003e\u003ca href\u003d\"#\" onclick\u003d\"Javascript:loadContent(\u0027clubID\u003d1329\u0026compID\u003d6785\u0026leagueTable\u003dY\u0026colour\u003d1E58AC\u0027);\"\u003eClashmore/Kinsalebeg\u003c/a\u003e\u003c/span\u003e\u0026nbsp;1-9\u0026nbsp;V\u0026nbsp;0-8\u0026nbsp;\u003cspan class\u003d\"teams\"\u003e\u003ca href\u003d\"#\" onclick\u003d\"Javascript:loadContent(\u0027clubID\u003d2060\u0026compID\u003d6785\u0026leagueTable\u003dY\u0026colour\u003d1E58AC\u0027);\"\u003eAn tSráidbhaile\u003c/a\u003e\u003c/span\u003e\n\t\t\t\u003c/p\u003e\n\t\t\t\u003cp\u003e\n\t\t\t\tTime: 8 00 PM , Venue: Fraher Field\n\t\t\t\u003c/p\u003e\n\t\t\t\u003cp\u003e\n\t\t\t\tReferee: John Condon\n\t\t\t\u003c/p\u003e\n\t\t\u003c/li\u003e\n\t\u003c/ul\u003e\n\u003c/div\u003e\n\u003cdiv class\u003d\"aFixture\" style\u003d\"display:none;\"\u003e\n\t\u003ch5 class\u003d\"primaryColor\"\u003e29.04.12 (Sun)\u003c/h5\u003e\n\t\u003cul class\u003d\"fixtures_list\"\u003e\n\t\t\u003cli\u003e\n\t\t\t\u003cp style\u003d\.....

I wish to traverse this data using Beautiful Soup, the data itself is all HTML code. I want it in format:

<div id="fixtures"><div class="aFixture>...... etc...

As one can see the '<', '=' symbols are represented by their UNICODE value rather than the relevant character.

4
  • Sounds cool - good luck! Jan 15, 2013 at 20:56
  • maybe you can find some Information here: perldoc.perl.org/perlunifaq.html
    – fanlim
    Jan 15, 2013 at 21:50
  • Please provide an actual example of incoming data and preferable its format specification, too, if available, and your Perl code. You might be trying to process data with encoded representations (“escape notations”) for characters as if it were plain text as such. Jan 15, 2013 at 22:14
  • Thank you fanlim, I will go through that. Examples added, Jukka.
    – chillok
    Jan 15, 2013 at 23:38

1 Answer 1

2

The choice of format used for the output is dumb. Instead of returning JSON, it's returning JavaScript code that calls a JQuery function.

First, extract the JSON.

my ($json) = $content =~ /^parseJSON\((.*)\)$/;

Then, just parse it with your favorite JSON parser.

use JSON::XS qw( decode_json );
my $html = decode_json($json)->{content};

Output:

<div id="fixtures">
...
3
  • Getting a strange error on that, after installing JSON:XS - "Can't locate common/sense.pm in @INC (...".
    – chillok
    Jan 16, 2013 at 1:05
  • No idea how you "installed" JSON::XS, but you did it wrong. Its dependency (common::sense) didn't get installed, and it wouldn't have passed testing without it. Installing common::sense might be enough, or you might have to reinstall JSON::XS properly. (cpan JSON::XS, usually.)
    – ikegami
    Jan 16, 2013 at 1:42
  • Installed via cpan JSON::SX previously, 'Going to read '/Users/User/.cpan/Metadata' Database was generated on Wed, 16 Jan 2013 00:41:03 GMT JSON::XS is up to date (2.33).' - Will go ahead and install common sense now.
    – chillok
    Jan 16, 2013 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.