Created
August 30, 2012 23:51
-
-
Save johndavidback/3545595 to your computer and use it in GitHub Desktop.
Get Google Plus Ones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib2 import urlopen | |
import re | |
def get_plus_ones(url): | |
""" | |
Get Google Plus ones | |
""" | |
# Build the url | |
url = 'https://plusone.google.com/_/+1/fastbutton?url=' + url | |
# Open said URL | |
response = urlopen(url) | |
# Get the data | |
data = response.read() | |
# Build the filter, we want what's in this: {c: 1234.0}, where 1234 is the number of plus ones | |
filter = re.compile("\{c: \d+.") | |
result = filter.findall(data) | |
# So now we should have something that looks like ['{c: 1234.'], so we want to grab out the characters after 4 that | |
# are not a period. | |
ones = result[0][4:len(result[0])-1] | |
try: | |
return int(ones) | |
except: | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has changed the face of programming.