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 17356dc commit 19bbea3
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions scraper.pl
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# This is a template for a Perl scraper on morph.io (https://morph.io)
# including some code snippets below that you should find helpful

# use LWP::Simple;
# use HTML::TreeBuilder;
# use Database::DumpTruck;

# use strict;
# use warnings;

# # Turn off output buffering
# $| = 1;

# # Read out and parse a web page
# my $tb = HTML::TreeBuilder->new_from_content(get('http://example.com/'));

# # Look for <tr>s of <table id="hello">
# my @rows = $tb->look_down(
# _tag => 'tr',
# sub { shift->parent->attr('id') eq 'hello' }
# );

# # 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'
# }]);

# You don't have to do things with the HTML::TreeBuilder and Database::DumpTruck libraries.
# You can use whatever libraries you want: https://morph.io/documentation/perl
# All that matters is that your final data is written to an SQLite database
# called "data.sqlite" in the current working directory which has at least a table
# called "data".
use LWP::Simple;
use HTML::TreeBuilder;
use Database::DumpTruck;

use strict;
use warnings;

# Turn off output buffering
$| = 1;

my $stringToFind = "XXXXXXXX";

# Read out and parse a web page
my $tb = HTML::TreeBuilder->new_from_content(get('https://www.win2day.at/gewinner-des-tages/'));

# Look for <tr>s of <table id="hello">
my @rows = $tb->look_down(
_tag => 'tr',
sub { shift->parent->attr('id') eq 'hello' }
);

# Check if our string was found
foreach my $row (@rows) {
if($row->as_text =~ m/\Q$stringToFind\E/) {
# print "String gefunden: $stringToFind\n";
last;
}
}

# 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'
}]);

0 comments on commit 19bbea3

Please sign in to comment.