Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created March 10, 2012 22:28
Show Gist options
  • Save davidwtbuxton/2013644 to your computer and use it in GitHub Desktop.
Save davidwtbuxton/2013644 to your computer and use it in GitHub Desktop.
Scrape metacritic for scores
#!/usr/bin/env python
# http://www.reddit.com/r/learnpython/comments/qqnqt/metacritic_score_grabber/
import urllib2
import re
url = 'http://www.metacritic.com/game/xbox-360/mass-effect-3'
r = urllib2.urlopen(url)
html = r.read()
user_score = r'<span class="score_value">([\d\.]+)</span>'
meta_score = r'<span class="score_value" property="v:average">([\d\.]+)</span>'
uscore = re.compile(user_score)
mscore = re.compile(meta_score)
scores = {
'u': uscore.search(html),
'm': mscore.search(html),
}
for key, value in scores.items():
if value is not None:
scores[key] = float(value.groups()[0])
if (scores['u'] is not None) and (scores['m'] is not None):
scores['c'] = ((scores['m'] / 10.0) + scores['u']) / 2.0
for key, value in scores.items():
print key, value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment