Thread Anpassung eines Perl Skripts (4 answers)
Opened by Jens4711 at 2013-10-23 23:42

Gast Jens4711
 2013-10-23 23:42
#171444 #171444
Hallo zusammen

ich habe ein Perl-Skript welchs ich anpassen möchte. Da ich erst seit heute mich mit Programmieren als solches und dazu dann mit Perl beschäftige weiss ich noch nicht so recht wo ich anpacken muss oder welches vielleicht die Befehle sind die ich brauche.

Das was ich ändern möchte habe ich als kommentare in das Script geschrieben.
Ich hoffe es kann mir jemand helfen:

Code (perl): (dl )
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use IO::File;
use POSIX qw(tmpnam);
use DEiXToBot;
use WWW::Selenium;

my $agent = DEiXToBot->new();

my $sel = WWW::Selenium->new( host => "localhost",
                              port => 4444,
                              browser => "*firefox",
                              browser_url => "http://www.finanznachrichten.de/"
                            );
$sel->start;

for my $i (1..3000) {
# --> load urls form a txt file one after each other
#    --> load/open file InputURLs.txt and go to line $i
#    --> make my $url = the current line[/b]

    my $url = "..."; # <-- something new needed here!??

    $sel->open($url);

    $sel->wait_for_page_to_load(5000);

    $sel->pause(1);

    print "$i) $url\n";

    print $fh $content;
    close $fh;

    $agent->get("file://$name"); 

    unlink $name; 

    if (! $agent->success) { die "Could not fetch the temp file!\n"; }

    $agent->build_dom();

    $agent->load_pattern('C:\Users\myName\Documents\Privat\MyCase3\Deixto Patterns\ExtractLinksToContent.xml');

    $agent->extract_content();
#-------------------------------------------------------------------------------------------> I'm not sure if I need this???
    if (! $agent->hits) {
        die "Could not find any MPs/ records!\n";
    }
    else {
        for my $record ($agent->records) {
            my @rec = @$record;

            my $party;
            my $logo = $rec[0];

           
            if ($logo=~m#ND_Logo#) { $party = "N.D. (New Democracy)"; }
            elsif ($logo=~m#COALITION#) { $party = "SYRIZA Unitary Social Front"; }
            elsif ($logo=~m#PASOK#) { $party = "PA.SO.K. (Panhellenic Socialist Movement)"; }
            elsif ($logo=~m#ANEKS_ELL#) { $party = "ANEXARTITOI ELLINES (Independent Hellenes)"; }
            elsif ($logo=~m#xrisi#) { $party = "LAIKOS SYNDESMOS - CHRYSI AVGI (People's Association - Golden Dawn)"; }
            elsif ($logo=~m#small#) { $party = "DHM.AR (Democratic Left)"; }
            elsif ($logo=~m#KKE#) { $party = "K.K.E. (Communist Party of Greece)"; }
            elsif ($logo=~m#INDEPENDENT#) { $party = "INDEPENDENT"; }
            else { die "$logo => Unknown logo!\n"; }

            $rec[0] = $party;

            $rec[3]=~s#\s+# #g; 
#---------------------------------------------------------------------------------------------->

            open my $fh,">>:utf8","ContentLinks.txt";
            print $fh join("\t",@rec)."\n";
            close $fh;
        }
    }
        # --> Find the "Weiter >>" Button on the page and click it until there is no "Weiter >>" button anymore. restart at wait for page to load (line 30)
}

$sel->stop;


modedit Editiert von GwenDragon: Code-Formatierung repariert
Last edited: 2013-10-24 08:55:47 +0200 (CEST)

View full thread Anpassung eines Perl Skripts