Projects‎ > ‎

NextBus Scraper


VBScript to get the next two bus arrival times from The primary motivation for this was to use it with Samurize, a system monitoring and desktop enhancement engine for Windows so that I could have the bus arrival times available for quick reference on screen instead of opening the website. A sample NextBus Samurize config is also available.

How Does It Work?

NextBus doesn't have an API so the page must be scraped. On the website, an iframe points to which actually contains the predictions. The page could be parsed (it's tricky since there are no id's or names for the elements) but for now we can use a hack - the title of the page is set to the next two arrival times by JavaScript. We can look for that section of the code and read the next two values. If there is no prediction, those values will be empty and we can detect that condition and react appropriately. There doesn't seem to be any simple or consistent way to present the values for the route, destination etc parameters so the user must explicitly specify them all. These can be easily read from the bookmarkable page URL for any route.

For example, the URL for the Georgia Tech Green Route, heading to 14th Street, for the stop at Ferst Drive and Atlantic Drive is

where a = agency, r = route/line, d = direction, s = stop [where you'll board] and ts = stop [where you'll disembark].

How Do I Use It?

Like mentioned above, the values of the parameters need to be read from the URL. There are three functions that you can use all of which take the same arguments - agency, route, direction, from (the boarding stop), destination.

NextArrivalTime - Returns the first next arrival time in minutes. For example, 33.
SecondArrivalTime - Returns the second next arrival time in minutes. For example 5.
NextTwoArrivalTimes - Returns both the arrival times, in minutes, separated by an ampersand (&) with a space before and after the ampersand. For example 17 & 56.


You can find the script (NextBusScraper.vbs) in the attachment on this page, below.

There is also a sample Samurize config to display the NextBus times for the Georgia Tech Green Route - here's what it looks like:

Grab the NextBus-Samurize-Config.sam attachment on this page. The Samurize Package (the .sam archive) is the same format as a ZIP archive so you can unzip it if you want and extract just the files you want/need. But importing the package using the Samurize Config Tool is the recommended way of getting started with minimal effort.
Dec 15, 2009, 11:41 AM
Dec 14, 2009, 11:20 PM