perl 中怎样用post提交form?该用哪个模块?如何获得提交后所得到的页面的源码?

zhouxiaoju 2007-10-31 02:03:27
我要往一个网页里提交一个form,获得提交后得到的网页的源代码,该怎么办?要用到CGI的模块吗?
form用post的方式提交,比如说:http://data.bls.gov/cgi-bin/srgate,提交一个serial_id:EIUIV131, 点击“Retia data”提交,就会获得一个含有数据的页面。如果用perl sript来进行这个过程,并获得含有数据页面的源码,该怎么样写这个部分的代码?要用到哪些模块?
...全文
286 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yakai 2009-01-24
  • 打赏
  • 举报
回复
use LWP::UserAgent;

$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(POST => 'http://data.bls.gov/cgi-bin/srgate');
$req->content_type('application/x-www-form-urlencoded');

$req->content('serial_id:EIUIV131'); # 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 $res->content;
}
else {
print $res->status_line, "\n";
}

2,204

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧