2017-09-13 124 views
1

我想編寫腳本來自動幫助我預訂網站的時間段。由於我想預訂週一至週五,我寫的腳本會彈出瀏覽器中的五個選項卡system("start $book")我可以在完成預訂後關閉選項卡嗎?以下是我的示例代碼。使用perl打開和關閉網頁

use Time::Local; 
use POSIX; 


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

my $today = time(); 
my $seconds = 24*60*60; 
my @gmtime = gmtime(); 
[email protected]; 
$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

爲什麼不使用[Win32 :: OLE](http://search.cpan.org/~jdb/Win32-OLE-0.1712/lib/Win32/OLE.pm),那麼你可以完成後退出? –

+0

嗨@GerhardBarnard,我是perl中的新成員,不知道如何在腳本中使用這個'Win32 :: OLE',你能告訴我一個例子嗎?謝謝 – Tim

+0

在下面的答案中看到一個簡單的演示。您可以在[Win :: OLE](http://search.cpan.org/~jdb/Win32-OLE-0.1712/lib/Win32/OLE.pm)頁面找到更多幫助 –

回答

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

+0

嗨,我已經嘗試了上面的代碼,但這次是彈出一個新的IE窗口,窗口不關閉。 – Tim

+0

你可以再試一次嗎? –

+0

是的,我嘗試其他網站的工作,但由於我想要達到的網站是.cgi格式,所以我認爲是我想要達到的網站的問題。謝謝 – Tim