How to get the number of Facebook Likes with Python

SEO metrics – Facebook Likes

Among the SEO metrics it is often useful to know how many of Facebook Likes are recognized for a particular site, or in more depth for a particular page that has been linked (either by the person concerned, but also by others) in some posts on Facebook. Often the popularity of a page, or rather its appreciation, may be a very good indicator, if not a metric SEO, to know the success or failure of a campaign or a particular post.

SEO - Facebook Likes get the number with Python

SEOLIB – a useful library for SEO

Python is a programming language that lends itself well to data analysis. Moreover, the ease with which you can write a script and use it as a great tool for doing SEO investigations, makes it a great tool for anyone who carries out an activity of webmastering or marketing surveys. Python is a very useful language in this regard, because of the extensive number and variety of libraries that allow you to apply it in many areas. In PyPI repository (where available all the Python libraries) there is a library that provides a number of useful tools for SEO. This library is called seolib.

To install it on your computer, you have to write the following command from a command line:

pip install seolib

Then once you have installed the seolib package, you can import the module directly within a Python session.

import seolib

You can import the seolib module within the code too, if you need to perform more complex tasks.

How to get the Facebook Likes with seolib

To obtain the number of Facebook Likes assigned to particular site, the seolib library provides the get_facebook_likes () function that takes one argument, the URL of the site you want to analyze:

import seolib as seo

likes = seo.get_facebook_likes('http://www.meccanismocomplesso.org')
print likes  # for Python 2.7  ,on Python 3.x use print(likes)

if you execute the code you will get the number of likes assigned to the Meccanismo Complesso web site.

88

But you might also be interested in the number of likes assigned to a particular page of your site, in this case, you have to extend the URL passed as an argument including the whole URL of the page

likes = seo.get_facebook_likes('http://www.meccanismocomplesso.org/python')

Finally, you can also get the likes directly assigned to any page, post or image  posted on Facebook (if you are not using the Web sites for promotion).

likes = seo.get_facebook_likes('http://www.facebook.com/meccanismocomplesso/')

Conclusions

If you are interested in more information about the seolib library, and its functions, I recommend you to read the official documentation (see here). Otherwise you will find more information and tutorials within the Python section of the Meccanismo Complesso site, in particular looking for the SEO & Webmastering (see here).[:]

Leave a Reply