Online Book Reader

Home Category

Webbots, Spiders, and Screen Scrapers - Michael Schrenk [95]

By Root 308 0
a period, you will specify the time of day you want your webbot to execute. You can also specify whether the webbot will run every day or only on weekdays, as shown in Figure 23-4. You can even schedule a webbot to skip one day or more.

Additionally, you can set the entire schedule to begin sometime in the future. For example, the configuration shown in Figure 23-4 will cause the webbot to run Monday through Friday at 6:20 PM, commencing on January 16, 2008.

Figure 23-4. Configuring the time and days your webbot will run

The final step of the scheduling wizard is to enter your Windows username and password, as shown in Figure 23-5. This will allow your webbot to run without Windows prompting you for authentication.

Figure 23-5. Entering a username and password to authenticate your webbot

On completing the wizard, the scheduler displays your new scheduled task, as shown in Figure 23-6.

Figure 23-6. The Task Scheduler showing the status of test_webbot's schedule

Complex Schedules

There are several ways to satisfy the need for a complex schedule. The easiest solution may be to schedule additional tasks. For example, if you need to run a webbot once at 6:20 PM and again at 6:45 PM, the simplest solution is to create another task that runs the same webbot at the later time.

The Task Scheduler is also capable of managing very complex schedules. If you right-click your webbot in the Task Scheduler window, select the Schedule tab, and then click the Advanced button, you can create the schedule shown in Figure 23-7, which runs the webbot every 10 minutes from 6:20 PM to 9:10 PM, every weekday except Wednesdays, starting on January 16, 2008.

Figure 23-7. An advanced weekly schedule

If a monthly period is required, you can specify which month and days you want the webbot to run. The configuration in Figure 23-8 describes a schedule that launches a webbot on the first Wednesday of every month.

Figure 23-8. Scheduling webbots to launch monthly

Non-Calendar-Based Triggers

Calendar events, like those examined in this chapter, are not the only events that may trigger a webbot to run. However, other types of triggers usually require that a scheduled task run periodically to detect if the non-calendar event has occurred. For example, the script in the following listings uses techniques discussed in Chapter 15 to trigger a webbot to run after receiving an email with the words Run the webbot in the subject line.

First, the webbot initializes itself to read email and establishes the location of the webbot it will run when it receives the triggering email message, as shown in Listing 23-3.

// Include the POP3 command library

include("LIB_pop3.php");

define("SERVER", "your.mailserver.net"); // Your POP3 mail server

define("USER", "your@email.com"); // Your POP3 email address

define("PASS", "your_password"); // Your POP3 password

$webbot_path = "c:\\webbots\\view_competitor.bat";

Listing 23-3: Initializing the webbot that is triggered via email

Once the initialization is complete, this webbot attempts to make a connection to the mail server, as shown in Listing 23-4.

// Connect to POP3 server

$connection_array = POP3_connect(SERVER, USER, PASS);

$POP3_connection = $connection_array['handle'];

Listing 23-4: Making a mail server connection

As shown in Figure 23-5, once a successful connection to the mail server is made, this webbot looks at each pending message to determine if it contains the trigger phrase Run the webbot. When this phrase is found, the webbot executes in a shell.

if($POP3_connection)

{

// Create an array of received messages

$email_array = POP3_list($POP3_connection);

// Examine each message in $email_array

for($xx=0; $xx{

// Get each email message

list($mail_id, $size) = explode(" ", $email_array[$xx]);

$message = POP3_retr($POP3_connection, $mail_id);

// Run the webbot if email subject contains "Run the webbot"

if(stristr($message, "Subject: Run the webbot"))

{

$output = shell_exec($webbot_path);

echo "

$output 
";
Return Main Page Previous Page Next Page

®Online Book Reader