使用WWW :: Mechanize访问框架

时间:2018-02-09 09:37:05

标签: perl

我用的是 WWW::Mechanize模块 访问具有两个帧的URL。我在第一帧中输入一个单词并提交,然后下载第二帧中返回的数据。但不知何故,它会在访问第二帧时挂起。

网址

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>WWW</title>
<style>
body { font-family: Verdana; background-color:"#F0F0F0"; }
a { color:blue; text-decoration:none; }
a:hover {  color:red; }
.cbutton { font-size:12pt; font-weight=bold; color:black; }
.ctext { font-family: Verdana; font-size: 10pt; }
.clabel { font-family: Verdana; font-size: 10pt; }
</style>
</head>

<frameset rows="40%,*">
  <frame name="rtop" src="123.asp" target="rbottom">
  <frame name="rbottom" src="444.html" scrolling="auto">

  <noframes>
  <body>
  <p>123</p>
  </body>
  </noframes>

</frameset>
</html>

在链接它时,在第一帧结尾的HTML中提交标记

<td width=28% align=center>
<input type="submit" name="act" value="xxx" class="cbutton">

我的Perl代码

 #!c:\\perl\\bin

 use strict;

 use WWW::Mechanize;

 my $url      = "myurl";
 my $Part     = 'mykey';
 my $outfile1 = "out1.html";

 my $mech = WWW::Mechanize->new();

 $mech->get($url);
 $mech->follow_link(tag => "frame"); # open first frame in document
 $mech->field ('' => $Part);
 $mech->submit();
 $mech->follow_link(tag => "frame"); # open 2nd frame in document, where it hangs

 my $output_page = $mech->content();

 open(OUTFILE, ">$outfile1");
 print OUTFILE "$output_page";
 close(OUTFILE);

0 个答案:

没有答案