Leser: 26
1 2 3 4 5
use strict; use warnings; my $zeichenkette = '<b>das ist ein Test</b>'; my ($taginhalt) = $zeichenkette =~ m!<b>([^<]*)</b>!; print "Taginhalt: ", (defined($taginhalt) ? $taginhalt : 'leer')
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/perl -w
#! /usr/bin/curl
# Autofetch reviews
# ToDo
#print "To Do Reviews:\n";
$currentSoftware = 321234472;
getAllReviewstest();
sub getAllReviewstest()
{
$country="\nCOUNTRY: United States";
$store = 143441;
#print $country, "\n";
fetchReviews();
print "Content-Type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Reviews</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "$review\n";
print "</BODY>\n";
print "</HTML>\n";
}
sub getAllReviews()
{
$country="\nCOUNTRY: United States";
$store = 143441;
print $country, "\n";
fetchReviews();
}
sub fetchReviews()
{
# my $doit = qq{curl -s -A "iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2" -H "X-Apple-Store-Front: $store-1" 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8' | gunzip | xmllint --format -};
my $doit = qq{curl -s 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8'};
my $riz = `$doit`;
my @rizray = split('\n', $riz);
my @rizray = grep(!/string/, @rizray);
my @rizray = grep(!/key/, @rizray);
my @rizray = grep(!/dict/, @rizray);
my @rizray = grep(!/VBoxView/, @rizray);
my @rizray = grep(!/HBoxView/, @rizray);
my @rizray = grep(!/MatrixView/, @rizray);
my @rizray = grep(!/TextView/, @rizray);
my @rizray = grep(!/iTunes/, @rizray);
my @rizray = grep(!/LoadFrameURL/, @rizray);
my @rizray = grep(!/PathElement/, @rizray);
my @rizray = grep(!/Protocol/, @rizray);
my @rizray = grep(!/ScrollView/, @rizray);
my @rizray = grep(!/Category.*/, @rizray);
my @rizray = grep(!/Color/, @rizray);
my @rizray = grep(!/Released.*/, @rizray);
my @rizray = grep(!/Seller.*/, @rizray);
my @rizray = grep(!/Rated.*/, @rizray);
my @rizray = grep(!/Rate this.*/, @rizray);
my @rizray = grep(!/©.*/, @rizray);
my @rizray = grep(!/.*MB/, @rizray);
my @rizray = grep(!/Version.*/, @rizray);
my @rizray = grep(!/.*2009/, @rizray);
my @rizray = grep(!/Infrequent.*/, @rizray);
my @rizray = grep(!/NEW.*/, @rizray);
my @rizray = grep(!/LANGUAGES.*/, @rizray);
my @rizray = grep(!/REQUIREMENTS.*/, @rizray);
my @rizray = grep(!/Apple.*/, @rizray);
my @rizray = grep(!/All rights.*/, @rizray);
my @rizray = grep(!/Policy.*/, @rizray);
my @rizray = grep(!/Terms of.*/, @rizray);
my @rizray = grep(!/Compatible.*/, @rizray);
my @rizray = grep(!/Requires.*/, @rizray);
my @rizray = grep(!/English.*/, @rizray);
my @rizray = grep(!/<b>.*/, @rizray);
my @rizray = grep(!/normalStyle/, @rizray);
my @rizray = grep(!/GotoURL/, @rizray);
my @rizray = grep(!/Sort by:/, @rizray);
my @rizray = grep(!/by.*/, @rizray);
#my @rizray = grep(!/">$/, @rizray);
my @rizray = grep(!/Copyright/, @rizray);
my @rizray = grep(!/> \/</, @rizray);
my @rizray = grep(!/>..</, @rizray);
foreach my $item (@rizray)
{
# print $item, ": ";
#$item =~ s/.*">//;
#$item =~ s/<.*//;
$review = "$review$item";
}
}
2009-10-27T18:30:18 pqalso in dem beispiel-link kommt überhaupt kein <b> vor.
aber das skript könnte wirklich *wesentlich* kürzer sein, diese mehrfache zuweisung an das array unten hat einen preis verdient, wie man ein skript unwartbar und riesengross macht.
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
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/perl -w
use LWP::Simple;
use strict;
# ToDo
#print "To Do Reviews:\n";
my $currentSoftware ='321234472';
my $country ="\nCOUNTRY: United States";
my $store ='143441';
getAllReviewstest($country,$store,$currentSoftware);
sub getAllReviewstest()
{
#print $country, "\n";
print "Content-Type: text/html\n\n";
my $review=fetchReviews(@_);
print <<EOT;
<HTML>
<HEAD>
<TITLE>Reviews</TITLE>
</HEAD>
<BODY>$review</BODY>
</HTML>
EOT
}
sub getAllReviews()
{
my ($country,$store,$currentSoftware)=@_;
print $country, "\n";
print fetchReviews($store,$currentSoftware);
}
sub fetchReviews()
{
my ($store,$currentSoftware)=@_;
# my $doit = qq{curl -s -A "iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2" -H "X-Apple-Store-Front: $store-1" 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8' | gunzip | xmllint --format -};
# my $doit = qq{curl -s 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8'};
# my $riz = `$doit`;
# "get" stammt von "LWP::Simple";
my $riz=get("http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8");
my @rizray = split('\n', $riz);
# "|" bedutet "oder" in regulären Ausdrücken
@rizray = grep(!/string|key|dict|VBoxView|HBoxView|MatrixView|TextView|iTunes|LoadFrameURL|PathElement|Protocol|ScrollView|Category.*|Color|Released.*|Seller.*|Rated.*|Rate this.*|©.*|.*MB|Version.*|.*2009|Infrequent.*|NEW.*|LANGUAGES.*|REQUIREMENTS.*|Apple.*|All rights.*|Policy.*|Terms of.*|Compatible.*|Requires.*|English.*|normalStyle|GotoURL|Sort by:|by.*|Copyright|> \/<|>..</, @rizray);
my $review join('',@rizray);
$review=~s!<b>\s*\S+\s*</b>\s*-\s*-!!gs;
return $review;
}
1 2 3 4 5 6 7 8 9 10 11 12
use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_string(<<"EOT"); <foo> <blubb><b >username</b> </blubb><b>nochn username</b> </foo> EOT my @names = map { $_->textContent } $doc->findnodes("//b"); print for @names;
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
use 5.010; use strict; use warnings; 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/' }; # Get application ID from command line or use default my $appid = $ARGV[0] // '321234472'; # Create XML parser object and XPath context my $libxml = XML::LibXML->new(); my $xpath = XML::LibXML::XPathContext->new(); $xpath->registerNs(itms => APPLE_ITEMS_NS); # Format URL using template and application ID, load content and parse XML my $document = $libxml->parse_string(get(sprintf(URL_TEMPLATE, $appid))); # Extract all <b>-tags from the XML data my @bs = $xpath->findnodes('//itms:b', $document); # Print the text contained in the extracted tags say $_->textContent foreach (@bs);
2009-10-27T21:06:23 Hunnenkoenig[...]
Was kann ich machen, damit es mit 5.8 funzt?
QuoteZum 2. punkt.... öhm...womit dann?
QuoteIch will das ja auf einer website abrufen und das resultat in eine PHP seite einbinden.
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
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 <b>-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);
#!/usr/bin/perl
2009-10-28T13:37:34 Hunnenkoenig
2009-10-28T14:28:48 HunnenkoenigWas du verlinkst, ist eine ältere version von dem, was ich verlinkt habe.
2009-10-28T15:12:40 HunnenkoenigUnd wenn das so ist, was ist das dann ein modul, dieses c-lib ding? Wofür ist das gut? Ist das Perl? (ne)... ist das linux oder apache oder PHP oder was?
$review =~ s!<b>\s*\S+\s*</b>\s*-\s*-!!g;
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
43
44
45
46
47
48
49
50
51
#! /usr/bin/perl -w
#! /usr/bin/curl
# Autofetch reviews
# ToDo
#print "To Do Reviews:\n";
$currentSoftware = 321234472;
getAppinfo();
sub getAppinfo()
{
fetchInfo();
print "Content-Type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>AppInfo</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "$review\n";
print "</BODY>\n";
print "</HTML>\n";
}
sub fetchInfo()
{
my $doit = qq{curl -s 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8'};
my $riz = `$doit`;
my @rizray = split('\n', $riz);
my @rizray = grep( !/key/ & !/string/ & !/PathElement/ & !/more games.*/
& !/iTunes/ & !/Category.*/ & !/GotoURL/ & !/normalStyle/ & !/Released.*/
& !/Seller.*/ & !/Rated.*/ & !/Rate this.*/ & !/©.*/ & !/Color/ & !/.*MB/
& !/Version.*/ & !/.*2009/ & !/Infrequent.*/ & !/NEW.*/ & !/LANGUAGES.*/
& !/REQUIREMENTS.*/ & !/Apple.*/ & !/All rights.*/ & !/Policy.*/ & !/Terms of.*/
& !/Compatible.*/ & !/Requires.*/ & !/English.*/ & !/Copyright/, @rizray);
foreach my $item (@rizray)
{
$review =~ s!by\s*<b>.*</b>\s*-\s*-!!g;
$review = "$review$item";
}
}
gut
28. Oct 2009 21:15 HunnenkoenigSprichst du jetzt von dem zweiten script den ich gepostet habe? Weil da ist keine sort by und das andere ding mehr drinn.
28. Oct 2009 21:15 HunnenkoenigMit aneinander hängen meinst du jetzt die !/blahblah/ & !/blahblah/ teile?
28. Oct 2009 21:30 HunnenkoenigIch habe jetzt diese Twig installiert. Keine ahnung was ich damit jetzt mache...
Wie ich sehe, da muss ich immernoch programmieren...
document/protocol/dict/dict/array/dict/0/array/dict/0/string/1
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 43 44 45 46 47
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use XML::Simple; my $currentSoftware = 321234472; my $data=get("http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=$currentSoftware&mt=8"); my $ref = XMLin($data); print display_tree($ref,''); sub display_tree { my $ref=shift; my $shiftin=shift || ''; my $ret=''; if(ref($ref) eq 'ARRAY') { for my $cnt (0..$#$ref) { $ret.=$shiftin.$cnt; my $lst=display_tree($ref->[$cnt],$shiftin." "); if(index($lst,"\n")>-1) { $ret.=":\n".$lst; } else { $ret.="=$lst\n"; } } } elsif(ref($ref) eq 'HASH') { for my $key (sort keys(%$ref)) { $ret.=$shiftin.$key; my $lst=display_tree($ref->{$key},$shiftin." "); if(index($lst,"\n")>-1) { $ret.=":\n".$lst; } else { $ret.="=$lst\n"; } } } else { $ref=~s/[\n\r]/ /gs; $ret=$ref; } return $ret; }
1 2 3 4 5 6 7 8
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use XML::Simple; use CGI; print CGI->header();