So I wrote a very simple DMOZ parser and downloader.
Im running an array of 4380 URLs which get downloaded, the html stripped, then it discards the site and moves on. Its a proof of concept to see how long it will take to download a massive amount of sites using LWP and a couple other modules.
After about 2200 URLs I get a seg fault.
This is the code
#!/usr/bin/perl
require LWP::UserAgent;
use HTML::FormatText;
use Time::HiRes;
require HTML::TreeBuilder;
print "Opening fetch file...\n";
#Open the DMOZ file
open(tmp, "Top/Arts/Movies/domains");
@domains = <tmp>;
close(tmp);
#set variables used to output later
$count=0;
$interval=1;
foreach(@domains) {
$count++;
$domain = "http://" . $_;
$start = Time::HiRes::time();
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get($domain);
if ($response->is_success) {
$content = $response->content; # or whatever
}
else {
$response->status_line;
}
$tree = HTML::TreeBuilder->new->parse_file("file.html");
$formatter = HTML::FormatText->new(leftmargin => 0, rightmargin =>
+ 50);
$end = Time::HiRes::time();
$time = $end-$start;
$total += $time;
if($total >=(10*$interval) ) {
print "$count sites in $total seconds\n";
$interval++;
}
}
Any suggestions as to why this is seg faulting?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.