Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created June 28, 2011 06:53
Show Gist options
  • Save hanksudo/1050637 to your computer and use it in GitHub Desktop.
Save hanksudo/1050637 to your computer and use it in GitHub Desktop.
Fetch data from SC2 battle.net then save to Google spreadsheet - fetch_info
# fetch info
# -*- coding: utf-8 -*-
import urllib2, re
from BeautifulSoup import BeautifulSoup
def fetch_info(url):
data = urllib2.urlopen(url).read()
soup = BeautifulSoup(data)
ladder = soup.findAll('div', {'class': 'ladder'})
if len(ladder) == 0:
return None, None
level_class = ladder[0].find('span')['class']
level = re.search('badge-([\w]+)', level_class).group(1)
race_class = soup.find('a', {'class': re.compile('race-') })['class']
race = re.search('(?<=-)\w+', race_class).group(0)
return level, race
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment