Last Updated: 20-August-2015

There are obviously dozens of reasons to want to see Twitter and FaceBook shares, so I have written a surprisingly simple script to do the job for me - I thought this would go into 50+ lines of code at least. Obviously this is only checking against one URL but a slight modification and I could feed in multiple URLs of competitors, a news or blog section or an entire site.

It's using the share apis and it parses the json data to display what we're after. You can go here to see the original data that is fetched -

As you can see the following is displayed :


Its the "Count":31 section we are after. Anyway the code and output are below!!

import requests
import json

url = ""
apis = ['', '']

# # facebook shares api
# # twitter shares api

for api in apis:
    r = requests.get(api + url)
    data = r.text
    x = json.loads(data) # now acts as a dict
    if 'shares' in x:
            print 'FaceBook shares', x['shares']
    elif 'count' in x:
            print 'Twitter shares', x['count']


adders@adders ~/Desktop/crawler $ python
FaceBook shares 9
Twitter shares 31

About the author


Craig Addyman @craigaddyman
Head of Digital Marketing. Python Coder.