forked from dpavlin/Biblio-Z3950
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScraper.pm
49 lines (35 loc) · 830 Bytes
/
Scraper.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package Scraper;
use warnings;
use strict;
use WWW::Mechanize;
sub new {
my ( $class, $database ) = @_;
$database ||= $class;
my $self = {
mech => WWW::Mechanize->new(),
database => $database,
};
bless $self, $class;
return $self;
}
sub save_marc {
my ( $self, $id, $marc ) = @_;
my $database = $self->{database};
mkdir 'marc' unless -e 'marc';
mkdir "marc/$database" unless -e "marc/$database";
my $path = "marc/$database/$id";
open(my $out, '>:utf8', $path) || die "$path: $!";
print $out $marc;
close($out);
warn "# created $path ", -s $path, " bytes";
}
our $dump_nr = 1;
sub save_content {
my $self = shift;
my $path = "/tmp/$dump_nr.html";
open(my $html, '>', $path);
print $html $self->{mech}->content;
close($html);
warn "# save_content $path ", -s $path, " bytes";
}
1;