1

I would like to write the scripts to auto help me book a time slot in a website. Since i want to book like Monday to Friday, the scripts i write will pop up five tab in the browser by system("start $book") can i close the tab after i done the booking? Below is my example code.

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");
}
5
  • 1
    why not use Win32::OLE then you could just quit when done?
    – Gerhard
    Sep 13, 2017 at 6:45
  • Hi @GerhardBarnard, i am new in perl and not sure how to use this Win32::OLE in my scripts, can you show me an example? Thanks
    – Tim
    Sep 13, 2017 at 6:53
  • see a simple demo in the below answer. You can find more help on the Win::OLE page
    – Gerhard
    Sep 13, 2017 at 7:01
  • Look at WWW::Mechanize::Firefox and WWW::Mechanize::Chrome. With those, you can easily build the whole booking process automatically.
    – simbabque
    Sep 13, 2017 at 8:11
  • Or Selenium::Remote::Driver if you actually want to control a web browser from your script. Sep 13, 2017 at 11:33

1 Answer 1

0

Using Win32::OLE you manipulate the application itself.

An example of how to use this:

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.

Obviously you would need to install the Win32::OLE module if you do not have it, by running cpan install Win32::OLE from cmd.

6
  • Hi, I has try the code above but this time is pop up a new IE window and the window is not closing.
    – Tim
    Sep 13, 2017 at 8:04
  • Can you try now again?
    – Gerhard
    Sep 13, 2017 at 8:17
  • yes, i try other website it work but since the website i want to reach is in .cgi format , so i think is the problem of the website i want to reach. Thanks
    – Tim
    Sep 13, 2017 at 8:24
  • Hint.. cgi is perl, perhaps look at alternative get requests?
    – Gerhard
    Sep 13, 2017 at 8:34
  • Which alternative get request can be use?
    – Tim
    Sep 13, 2017 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.