Thread grep <br> in text (26 answers)
Opened by Hunnenkoenig at 2009-11-20 12:34

murphy
 2009-11-22 17:40
#128443 #128443
User since
2004-07-19
1776 Artikel
HausmeisterIn
[Homepage]
user image
Falls das noch jemanden interessiert, hier wäre mal eine saubere Lösung zum Auslesen der gewünschten Informationen, allerdings unter Verwendung dafür geeigneter Bibliotheken:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;


Ohne Module aber mit externen Programmen würde ich vorschlagen, curl und xsltproc zu Hilfe zu nehmen, um den gleichen Effekt zu erreichen.
When C++ is your hammer, every problem looks like your thumb.

View full thread grep <br> in text