星星博客's Archiver

cnangel 发表于 2005-8-25 19:54

一个程序自动刷新页面的例子

[color=red]作者:小歪歪
日期:2001-1-12 15:49:23[/color]
[code]
#!/usr/bin/perl
  use HTTP::Request;
  use LWP::UserAgent;
  my $ua = new LWP::UserAgent;
  $|=1;
  print "content-type:text/html\n\n";
  $ua->agent("AgentName/1.0 " . $ua->agent);
  $ua->timeout(80);
  # Create a request
  my $req = new HTTP::Request POST => ';http://search.sina.com.cn/cgi-bin/search/search.cgi';;
  $req->content_type(';application/x-www-form-urlencoded';);
  my $buffer="ss=sina&_searchkey=%BB%EE%B6%AF%2B%BD%B1%CF%EE&_andor=and&s1=%CB%D1%CB%F7";
  $req->content($buffer);
  # Pass request to the user agent and get a response back
  my $res = $ua->request($req);
  # Check the outcome of the response
  if ($res->is_success) {
print length($res->content);
   print <<END;
<META HTTP-EQUIV="Refresh" Content=1;Host="http://***.***.***.***/nperl/autorefresh.pl">
END
;
print &#36;res->content ;
  
  } else {
print "bad luck";
  }[/code]

[color=#CC0000][b]——————以下内容由[u]Cnangel[/u]在[u]2005年08月25日 07:59pm[/u]时添加———————[/b][/color]

    不怎么高明,Perl是写socket的高手,为什么不用呢?

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.