Created
April 30, 2011 20:58
-
-
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
This file contains 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
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