use Encode;
use LWP::Simple;
sub URLEncode {
my $theURL = $_[0];
my $MetaChars = quotemeta( ';,/?\|=+)(*&^%$#@!~`:');
$theURL =~ s/([$MetaChars\"\'\x80-\xFF])/"%" . uc(sprintf("%2.2x", ord($1)))/eg;
$theURL =~ s/ /\+/g;
return $theURL;
}
my $start = '北京';
my $dest = '莱阳';
my $date = '2009-1-18';
my $url = 'http://www.huochepiao.com/City/Search.asp?leixing=' .
URLEncode('转让'). '&chufa=' . URLEncode($start) . '&daoda=' . URLEncode($dest);
#print $url;
my %result=();
#print $content;
while(1)
{
my $content = get $url;
die "Couldn't get $url" unless defined $content;
while($content =~ /href=([^ ]*htm)\s*target=_blank>[^<]*$start-$dest[^<]*$date<\/a>/g )
{
my $info="";
my $inurl = $1;
if(!defined($result{$1})) {
print $1 . "\n";
my $content2 = get $1;
#print $content2;
$content2 =~ /车 次:\s*<a href=[^>]*><b>([^><]*)/;
$info .= "车次: $1\n";
$content2 =~ /席 别:\s*([^<]*)<br>/;
$info .= "席 别:$1\n";
$content2 =~ /始发站:\s*([^<]*)<br>/;
$info .= "始发站:$1\n";
$content2 =~ /到达站:\s*([^<]*)<br>/;
$info .= "到达站:$1\n";
$content2 =~ /发布时间:\s*([^<]*)<\/TD>/;
$info .= "发布时间:$1\n";
$content2 =~ /发布人:\s*([^<]*)<a href="[^<>]*">/;
$info .= "发布人:$1\n";
$content2 =~ /电 话:\s*<a href="[^<>]*">([^<]*)<\/a>/;
$info .= "电话:$1 \n";
print $info;
print "-------------------\n";
$result{$inurl} = $info;
}
}
print "\n";
}