use 5.010; use strict; use warnings; use LWP::UserAgent; use XML::LibXML; use constant { AGENT_NAME => 'iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2', STORE_HEADER => 'X-Apple-Store-Front', URL_TEMPLATE => 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%s', ITMS_NS => 'http://www.apple.com/itms/', DESC_PATH => '//itms:TextView[.//text() = "APPLICATION DESCRIPTION"]/following-sibling::itms:TextView' }; # Get application and store ID from command line or use defaults my $app_id = $ARGV[0] // '321234472'; my $store_id = $ARGV[1] // '143441-1'; # Create HTTP user agent my $browser = LWP::UserAgent->new(agent => AGENT_NAME); $browser->default_header(STORE_HEADER, $store_id); # Create XML parser object and XPath context my $libxml = XML::LibXML->new(); my $xpath = XML::LibXML::XPathContext->new(); $xpath->registerNs(itms => ITMS_NS); # Format URL using template and application ID and load content my $response = $browser->get(sprintf(URL_TEMPLATE, $app_id)); die $response->status_line unless ($response->is_success); # Parse the XML document my $document = $libxml->parse_string($response->decoded_content); # Extract application description from the XML document my ($desc) = $xpath->findnodes(DESC_PATH, $document); die 'No description found' unless (defined($desc)); # Print the text contained in the extracted tag say $desc->textContent;