开发者

Opening Web Site

开发者 https://www.devze.com 2023-02-10 08:04 出处:网络
I\'m kind of new at Perl. A friend of mine asks me to write him a program that could search specific ad on his favourite boat for sale Web Site. It\'s a very convenient little program that will allow

I'm kind of new at Perl. A friend of mine asks me to write him a program that could search specific ad on his favourite boat for sale Web Site. It's a very convenient little program that will allow a user to search multiple Web Sites for specific ads.

Here is how it works. I load up the Web Page into a temporary file and search for matching ad and return the result. It works fine most of the time but I noticed that some site won't load up and I don’t know why.

Here is the script that loads the pages and stores it a temp file:

use LWP::UserAgent;

use HTTP::Response;

use URI::Heuristic;

unless (defined ($content = get ($URL) )) { print "could not get $UR开发者_如何学GoL <br>"; }

open (DATABASE, ">$web_page_file");

print DATABASE "$content";

close (DATABASE);
#

I've been successfully run it on many sites and it works fine. But recently, 2 sites won't load up. It's :

http://www.babord.ca

http://www.sailboatlistings.com

I have 2 Questions:

A) Can you tell me what is wrong with my script with these two sites?

B) More important, is there a diagnostic tool that can tell me what the problems are (for future problem site)?


The example you posted doesn't work at all for me, and you don't say exactly what isn't working with the two examples you give so it's tough to debug your sample. The below works and I think is a cleaner way of getting what you're looking for:

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;

my $URL = 'http://www.yourboatsite.com';
my $mech = WWW::Mechanize->new();  #Autocheck defaults to ON to check for success.
$mech->get($URL);  # Use :content_file option to auto-write to a file.

print $mech->content();

You also probably want to tag your entry as perl rather than mod-perl since it's not a mod_perl problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消