Parcourir la source

Scraping of Spore achievements

master
Chris Smith il y a 14 ans
Parent
révision
c18830c4ae
3 fichiers modifiés avec 2038 ajouts et 0 suppressions
  1. 2012
    0
      src/BeautifulSoup.py
  2. 23
    0
      src/Scraper.py
  3. 3
    0
      src/helloworld.py

+ 2012
- 0
src/BeautifulSoup.py
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 23
- 0
src/Scraper.py Voir le fichier

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

+ 3
- 0
src/helloworld.py Voir le fichier

1
 import cgi
1
 import cgi
2
+from Scraper import scraper
2
 
3
 
3
 from google.appengine.ext import webapp
4
 from google.appengine.ext import webapp
4
 from google.appengine.api import users
5
 from google.appengine.api import users
45
 
46
 
46
         self.show_footer()
47
         self.show_footer()
47
 
48
 
49
+        self.response.out.write(scraper().scrape_spore("csmith87"))
50
+
48
     def show_header(self):
51
     def show_header(self):
49
         self.response.out.write("""
52
         self.response.out.write("""
50
           <html>
53
           <html>

Chargement…
Annuler
Enregistrer