Skip to content

Instantly share code, notes, and snippets.

@johndavidback
Created August 30, 2012 23:51
Show Gist options
  • Save johndavidback/3545595 to your computer and use it in GitHub Desktop.
Save johndavidback/3545595 to your computer and use it in GitHub Desktop.
Get Google Plus Ones
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
@cridenour
Copy link

This has changed the face of programming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment