-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
use LWP::Simple; | ||
use HTML::TreeBuilder; | ||
use Database::DumpTruck; | ||
|
||
use strict; | ||
use warnings; | ||
use LWP::UserAgent; | ||
use Database::DumpTruck; | ||
|
||
# Turn off output buffering | ||
$| = 1; | ||
|
||
my $stringToFind = "XXXXXXXX"; | ||
# URL der Webseite und Suchbegriff | ||
my $url = 'https://www.win2day.at/gewinner-des-tages'; | ||
my $search_term = 'hanskues'; | ||
|
||
# Read out and parse a web page | ||
my $tb = HTML::TreeBuilder->new_from_content(get('https://www.win2day.at/gewinner-des-tages/')); | ||
# HTTP-Anfrage an die Webseite senden | ||
my $ua = LWP::UserAgent->new; | ||
my $response = $ua->get($url); | ||
|
||
# Look for <tr>s of <table id="hello"> | ||
my @rows = $tb->look_down( | ||
_tag => 'tr', | ||
sub { shift->parent->attr('id') eq 'hello' } | ||
); | ||
if ($response->is_success) { | ||
my $content = $response->decoded_content; | ||
|
||
# Check if our string was found | ||
foreach my $row (@rows) { | ||
if($row->as_text =~ m/\Q$stringToFind\E/) { | ||
# print "String gefunden: $stringToFind\n"; | ||
last; | ||
} | ||
# Suchbegriff in der Webseite finden | ||
if ($content =~ /$search_term/) { | ||
print "String gefunden: $search_term\n"; | ||
} | ||
else { | ||
die "Fehler beim Abrufen der Webseite: " . $response->status_line; | ||
} | ||
} | ||
|
||
# Open a database handle | ||
my $dt = Database::DumpTruck->new({dbname => 'data.sqlite', table => 'data'}); | ||
|
||
# Insert some records into the database | ||
$dt->insert([{ | ||
Name => 'Susan', | ||
Occupation => 'Software Developer' | ||
Name => 'Jagger78', | ||
}]); |