使用perl打开和关闭网页

时间:2017-09-13 06:38:12

标签: perl webpage

我想编写脚本来自动帮我预订网站的时间段。由于我想要像星期一到星期五那样预订,我编写的脚本将在浏览器中弹出五个标签system("start $book")我可以在完成预订后关闭标签吗?下面是我的示例代码。

use Time::Local;
use POSIX;


####### this week ##########

my $today = time ();
my $seconds = 24*60*60;
my @gmtime = gmtime ();
my@thisweek;
$today = $today - $gmtime[6] * $seconds;
for my $haha (0..4) {
    $today += $seconds;
    my @wday = gmtime ($today);
    push @thisweek,strftime ("%Y%m%d %Y%U", @wday);
}

($monday_1,$tuesday_1,$wednesday_1,$thursday_1,$friday_1) = @thisweek; 

book_time($monday_1,"1617");
book_time($tuesday_1,"1617");
book_time($wednesday_1,"1617");
book_time($thursday_1,"1617");
book_time($friday_1,"1617");

sub book_time()
{
my ($bookdate,$bookweek)= split " ",shift;
my $booktime= shift;
my $book = "http://www.example.com";
system("start $book");
}

1 个答案:

答案 0 :(得分:0)

使用Win32::OLE操纵应用程序本身。

如何使用它的一个例子:

use strict;
use warnings;
use Win32::OLE

my $my_page = Win32::OLE->new("InternetExplorer.Application"); # sets the app to open (IE)
   $my_page->{visible} = 1;    # sets whether the action is visible
   $my_page->Navigate("http://www.example.com"); # opens the page
   # ..do something while page is open...
   $my_page->Quit(); # close the page when done.

显然,如果您没有,请安装Win32::OLE模块,方法是从cmd运行cpan install Win32::OLE