use 5.008; use strict; use warnings; use utf8; use CGI; use LWP::Simple; use XML::LibXML; use constant { URL_TEMPLATE => 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%s&mt=8', APPLE_ITEMS_NS => 'http://www.apple.com/itms/' }; # Create CGI context, XML parser object and XPath context my $cgi = CGI->new(); my $libxml = XML::LibXML->new(); my $xpath = XML::LibXML::XPathContext->new(); $xpath->registerNs(itms => APPLE_ITEMS_NS); # Get application ID from query parameters or use default my $appid = $cgi->param('appid') || '321234472'; # Format URL using template and application ID, load content and parse XML my $document = $libxml->parse_string(get(sprintf(URL_TEMPLATE, $appid))); # Extract all -tags from the XML data my @bs = $xpath->findnodes('//itms:b', $document); # Print HTTP header and the text contained in the extracted tags print $cgi->header(-type => 'text/plain', -charset => 'utf-8'); print $_->textContent . "\n" foreach (@bs);