January 25, 2021
Hot Topics:

Tracking a FedEx Package with an HTML Scraper

  • By Jonathan Eisenzopf
  • Send Email »
  • More Articles »

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.

Hopefully many of your Web application have been componentized into re-usable libraries, so that other interfaces can be developed using the same code. In reality, most Web applications are flat scripts. Others are not even available to you at all. One way of leveraging Web applications in the latter two examples is to write a layer of code between the voice interface and an existing Web or wireless interface. This exercise involves emulating the intended client, submitting form input, and parsing results into a form that can be played back by a VoiceXML interface.

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 
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

This article was originally published on September 28, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date