Incomplete webapp to aggregate achievements/badges from various sources
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Scraper.py 942B

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