I have a couple of observations and some more questions.
will read the first line from the file. To look at each line in turn loop over the file handle with a while loop.my $pid = <PIDLIST>;
The docs for LWP::Simple show how to check if the get is successful. Always best to do that.
First question, what does a line in the pidlist.txt file actually look like? Is there any processing to be done to extract any data you need?
Secondly, could you show a (cut down) sample of what the downloaded content looks like. It may be that you can extract the data you need on the fly and write the whole lot out in one go rather than save each page to disk and parse it later.
Lastly, it looks as though the site needs a login and uses cookies. I'm curious to know how you managed to download any pages.
Looking good though!
This is some code illustrating the points above.
#! /usr/bin/perl use strict; use warnings; use LWP::Simple qw(get); use File::Slurp ; # pid = Persona ID, one of a players 3 identities. # sid = Sortie ID, identifier for a mission taken by the persona. # We want to crawl all sortie list pages and collect new sid's we # have't seen before and then move on to next persona. my $pbase = q{http://csr.wwiionline.com/scripts/services/persona/sorti +es.jsp}; my $pcnt = 1; my $pidfile = q{c:/scr/pidlist.txt}; # Open list of pid's open my $pidlist, q{<}, $pidfile or die qq{Could not open $pidfile: $! +}; # loop over list of pids one at a time while (my $pid = <$pidlist>){ print $pid; chomp $pid; # what does a line from the pidlist look like? # do need to do any work on it? while (1) { my $url = qq{$pbase?page=$pcnt&pid=$pid}; my $content = get($url); die qq{get failed for $url: $!} unless $content; # parse $content # extract data we need # test if there is more work to do # Update page number and grab next. $pcnt += 1; }; } # Close files close $pidlist or die $!; print qq{\nDone!\n};
In reply to Re^3: collect data from web pages and insert into mysql
by wfsp
in thread collect data from web pages and insert into mysql
by SteinerKD
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |