|
@@ -0,0 +1,23 @@
|
|
1
|
+from BeautifulSoup import BeautifulSoup
|
|
2
|
+import urllib2
|
|
3
|
+
|
|
4
|
+class scraper:
|
|
5
|
+
|
|
6
|
+ def scrape_spore(self, credentials):
|
|
7
|
+ results = []
|
|
8
|
+ url = "http://www.spore.com/view/achievements/%s" % credentials
|
|
9
|
+ try:
|
|
10
|
+ result = urllib2.urlopen(url).read()
|
|
11
|
+ soup = BeautifulSoup(result)
|
|
12
|
+ achdiv = soup.find('h2', 'achievementsH2').findNextSibling('div', 'fields')
|
|
13
|
+
|
|
14
|
+ for ach in achdiv.findAll('table'):
|
|
15
|
+ 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 = ach.find('span').string.strip()
|
|
19
|
+ results.append({'img': img, 'title': title, 'desc': desc, 'date': date})
|
|
20
|
+ except urllib2.URLError, e:
|
|
21
|
+ handleError(e)
|
|
22
|
+
|
|
23
|
+ return results
|