ignore ssl certificate errors
[Biblio-Z3950.git] / Scraper.pm
1 package Scraper;
2
3 use warnings;
4 use strict;
5
6 use WWW::Mechanize;
7
8 sub new {
9     my ( $class, $database ) = @_;
10
11         $database ||= $class;
12
13     my $self = {
14                 mech => WWW::Mechanize->new(),
15                 database => $database,
16         };
17     bless $self, $class;
18     return $self;
19 }
20
21 sub mech { $_[0]->{mech} }
22
23 sub save_marc {
24         my ( $self, $id, $marc ) = @_;
25
26         my $database = $self->{database};
27         mkdir 'marc' unless -e 'marc';
28         mkdir "marc/$database" unless -e "marc/$database";
29
30         my $path = "marc/$database/$id";
31
32         open(my $out, '>:utf8', $path) || die "$path: $!";
33         print $out $marc;
34         close($out);
35
36         warn "# created $path ", -s $path, " bytes";
37
38 }
39
40 our $dump_nr = 1;
41
42 sub save_content {
43         my $self = shift;
44         my $path = "/tmp/$dump_nr.html";
45         open(my $html, '>', $path);
46         print $html $self->{mech}->content;
47         close($html);
48         warn "# save_content $path ", -s $path, " bytes";
49         $dump_nr++;
50 }
51
52 1;