Skip to content

Commit

Permalink
Update scraper.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagger78 committed Apr 10, 2024
1 parent 19bbea3 commit 1732008
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions scraper.pl
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',
}]);

0 comments on commit 1732008

Please sign in to comment.