Skip to content

Instantly share code, notes, and snippets.

@karolk
Created April 30, 2011 20:58
Show Gist options
  • Save karolk/949989 to your computer and use it in GitHub Desktop.
Save karolk/949989 to your computer and use it in GitHub Desktop.
Check how many 'likes' a website's got if it uses Facebook like button
import urllib
import re
import sys
def fb_likes(url):
html = urllib.urlopen(url).read()
has_fb = re.search('<iframe src=\"http\:\/\/www.facebook.com', html)
if has_fb:
fb_iframe_url = re.search('<iframe src="(http\:\/\/www.facebook.com\S+)"', html).group(1)
fb_html = urllib.urlopen(fb_iframe_url).read()
likes = re.search('(\d+) like', fb_html)
if likes:
return likes.group(1)
def main():
if len(sys.argv)>1:
res = fb_likes(sys.argv[1])
if res:
print res
else:
print 'Couldn\'t found Facebook Like widget'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment