Incomplete webapp to aggregate achievements/badges from various sources
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Scraper.py 929B

12345678910111213141516171819202122232425
  1. from BeautifulSoup import BeautifulSoup
  2. from datetime import datetime
  3. import urllib2
  4. class scraper:
  5. def scrape_spore(self, credentials):
  6. results = []
  7. url = "http://www.spore.com/view/achievements/%s" % credentials
  8. fmt = "%a %B %d, %Y"
  9. try:
  10. result = urllib2.urlopen(url).read()
  11. soup = BeautifulSoup(result)
  12. achdiv = soup.find('h2', 'achievementsH2').findNextSibling('div', 'fields')
  13. for ach in achdiv.findAll('table'):
  14. results.append({'img': "http://www.spore.com%s" % ach.find('img')['src'],
  15. 'title': ach.find('b').string.strip(),
  16. 'desc': ach.find('div', 'achievementDesc').contents[0].strip(),
  17. 'date': datetime.strptime(ach.find('span').string.strip(), fmt)})
  18. except urllib2.URLError, e:
  19. handleError(e)
  20. return results