Using web scraping to follow your orders on Ticketmaster
The legendary rock’n'roll band AC/DC will land on brazilian soil for the second time in November, for what is considered to be the show of the decade around here! The tickets for their single concert, sold by the brazilian Ticketmaster, ran out in less than 48 hours. This concert is going to be amazing!
A lot of things happened during those 48 hous. The Ticketmaster staff had trouble to keep the website on-line, and due to the enormous load, it’s possible that only a few thousands of people had enough luck to buy their tickets via the website.
Also, Ticketmaster admits that the notification e-mails may not reach, which means we cannot rely on those to follow our orders. In fact, they recomend that customers check their orders manually once a day. Oh boy…
I hate to do certain tasks manually, specially the ones that can be automated. So, in this post I’ll show you a very simple Python-based command-line tool that displays the status of your Ticketmaster1 orders on the screen2, using a technique known as web scraping.
The code, which is also on Github, can be seen below:
#!/usr/bin/env python #-*- coding:utf-8 -*- import urllib import urllib2 import pynotify _BASE_URL = 'https://ticketing.ticketmaster.com.br' _LOGIN_URI = '%s/shwLogin.cfm' % _BASE_URL _ORDER_URI = '%s/shwCompraDetalhe.cfm?pedidoID=%%s' % _BASE_URL _ORDERS_LINK = '<a href="%s">More...</a>' % _LOGIN_URI _PRIORITY_LOW = pynotify.URGENCY_LOW _PRIORITY_NORMAL = pynotify.URGENCY_NORMAL _PRIORITY_CRITICAL = pynotify.URGENCY_CRITICAL _NOTIFICATION_TITLE = 'Ticketmaster Order %s' _STATUS_CODES = { 'Livre' : ('Not processed yet' , _PRIORITY_LOW), 'StdReserva' : ('Reserving your tickets' , _PRIORITY_NORMAL), 'StdCobranca': ('Charging your tickets' , _PRIORITY_NORMAL), 'VendaOk' : ('Billed' , _PRIORITY_CRITICAL), 'Recusada' : ('Rejected' , _PRIORITY_CRITICAL) } def initialize_notification_system(app_title): if not pynotify.init(app_title): import sys sys.exit(1) def display_message(title, message, priority=_PRIORITY_CRITICAL): message = pynotify.Notification(title, message) message.set_urgency(priority) message.show() def check_orders(email, password, order_ids): try: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) login(opener, email, password) try: for order_id in order_ids: show_order_status(opener, order_id) except: title = _NOTIFICATION_TITLE % order_id display_message(title, 'Cannot check status') except: display_message('Ticketmaster', 'Login failed') def login(opener, email, password): params = urllib.urlencode({'email': email, 'senha': password}) response = opener.open('%s?tentaLogin=1' % _LOGIN_URI, params) # Invalid credentials check if response.read().find('senha incorreta') >= 0: raise Exception def show_order_status(opener, order_id): response = opener.open(_ORDER_URI % order_id) content = response.read() # Search for the order status codes for key, value in _STATUS_CODES.items(): if content.find(key) >= 0: title = _NOTIFICATION_TITLE % order_id message = '%s. %s' % (value[0], _ORDERS_LINK) display_message(title, message, value[1]) break else: display_message(_NOTIFICATION_TITLE % order_id, 'Status not found') def main(): initialize_notification_system("Ticketmaster Order Status") import optparse p = optparse.OptionParser() # Required command line options p.add_option('--email' , '-e', help='E-mail address used in your Ticketmaster credentials.') p.add_option('--password' , '-p', help='Password used in your Ticketmaster credentials.') p.add_option('--order-ids', '-o', help='Order IDs to be checked, separated by collons.') options = p.parse_args()[0] if not options.email or not options.password or not options.order_ids: p.print_help() else: order_ids = map(lambda s: s.strip(), options.order_ids.split(',')) check_orders(options.email, options.password, order_ids) if __name__ == '__main__': main()
The reason I’ve used web scrapping is because the brazilian Ticketmaster doesn’t seem to provide an API the way Flickr does, for example. Nevertheless, the code is quite simple.
As you can see, it first fires a HTTP request to the login URI in order to validate the user credentials. If the authentication succeeds, our cookie-aware opener will get the session cookies from the server and use them on the following requests, which extract the current order status for each order ID.
Now, let’s give it a spin:
Finally, add a new entry to your crontab to run the script whenever you want (e.g. every 10 minutes):
*/10 * * * * python ticketmaster_order_status.py --email=your@email.com --password=passwd --order-ids=1234
Good luck and let there be rock!
- The script only works for the brazilian Ticketmaster website. ↩
- The script uses libnotify to display notifications on the screen, so don’t forget to install it. ↩



Hey there,
Just a little tip:
- You don’t need to use backslashes for line continuations on `p.app_option`: they’re already implied by the open parenthesis.
Cheers from a fellow Brazilian!
Thanks for the tip!
[...] was one of the lucky ones who lost their cellphones a few months ago, during that crazy AC/DC concert. Surprisingly, that didn’t upset me at all; although I’m not a heavy user, that was the [...]