Browse Source

Scraper for steam games page

master
Chris Smith 14 years ago
parent
commit
1bf9bef659
1 changed files with 21 additions and 0 deletions
  1. 21
    0
      src/Scraper.py

+ 21
- 0
src/Scraper.py View File

@@ -24,3 +24,24 @@ class Scraper:
24 24
           handleError(e)
25 25
 
26 26
         return results
27
+
28
+    @staticmethod
29
+    def scrape_steam(credentials):
30
+        results = []
31
+        prefix = "http://steamcommunity.com/id/%s/"
32
+        url = "%sgames?xml=1" % (prefix % credentials)
33
+
34
+        try:
35
+          result = urllib2.urlopen(url).read()
36
+          soup = BeautifulSoup(result)
37
+
38
+          for globalLink in soup.findAll('globalstatslink'):
39
+            game = globalLink.parent
40
+            name = game.find('name').string.strip()
41
+            url = prefix + game.find('statslink').string.strip()[len(prefix % credentials):]
42
+            results.append({'name': name, 'url': url})
43
+
44
+        except urllib2.URLError, e:
45
+          handleError(e)
46
+
47
+        return results

Loading…
Cancel
Save