1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use warnings;
use strict;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->timeout(30);
$mech->agent_alias('Windows Mozilla');
$mech->get('http://www.lirix.de/unbenannt.html');
my $test = $mech->find_link( class => 'testklasse' );
say $test;
#ODER
for my $test2 ($mech->find_all_links(class => "testklasse")) {
say $test2->text;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Unbenannte Seite</title>
</head>
<body>
<div class="testklasse">
<a href="http://www.spiegel.de">Testlink</a></div>
</body>
</html>
1
2
3
<div class="testklasse">
<a href="http://www.bla.com"><img src="bla.gif" alt="" height="32" width="32" border="0" /></a></p>
</div>
<a id="blamuh" name="blamuh" href="http://www.spiegel.de">Testlink</a>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div class="gelb">
<div class="hier">
<a href="#">Text</a>
</div>
<div class="hier">
<a href="#">Text</a>
</div>
<div class="hier">
<a href="#">Text</a>
</div>
<div class="hier">
<a href="#">Text</a>
</div>
</div>
print $mech->at( 'div.testklasse a' )->text;
1 2 3
use Mojo::DOM; my $mojo = Mojo::DOM->new( $mech->content); print $mojo->at( 'div.testklasse a' )->text;