Created
June 28, 2011 06:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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