-
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
37 additions
and
36 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,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' | ||
}]); |