Tracking a FedEx Package with an HTML Scraper
One way to develop powerful VoiceXML applications is to leverage existing Web applications by simulating a Web browser and scraping the results via a programmable HTTP Web agent. This example allows users to track a Federal Express package, using the fedex.com Web site.
One of the selling points of VoiceXML is that it can work with your existing Web infrastructure. Applications can be developed using the same tools, run on the same server over the same Internet connection. So it makes sense that VoiceXML applications should be able to leverage existing code.
The example that we're going to look at is a Perl script that uses the Federal Express Web tracking application available at http://www.fedex.com/us/tracking/. I will be referring to line numbers in the source code throughout this article, so you might want to open the example in another browser or print it out for reference. You can also download the code without line numbers.
The application is totally self-contained. There aren't any other external files or programs needed to run the script other than a Perl interpreter and the LWP and CGI modules. The script will run on Windows and Unix servers and on any Web server that supports CGI.
How it Works
An example of a typical dialog is below:
Computer: Please enter your federal express tracking number now. Customer: 1232343 Computer: Package 1232343 is as follows. Left FedEx Sort Facility NEWARK NEW JERSEY. The last update for this package occurred on August six at twelve thirty nine.
The first time the script is run, the user is prompted for their Fedex tracking number. If the
user doesn't enter a number, they are given additional instructions and prompted for the number
again. When the user enters a number on their telephone keypad, it's sent back to the script
as the track_num form field. This number is appended to the Fedex tracking URL and sent
using an LWP agent. LWP is a Perl library for simulating a Web browser agent. The page that
comes back from the Fedex site is parsed for the tracking information. We also check for an
error message. If an error occurred, the user is prompted again for a tracking number, otherwise,
the tracking information is played and the call is ended.
Page 1 of 2