2

I'm trying to scrape few news websites to extract information like title, content and timestamp. Now, I also want to count the number of times that article was shared on twitter and Facebook. However, I haven't been able to find a suitable resource to do it effectively. I'm using Python 2.7.4 and Beautiful Soup4 to extract data and dump it into a .CSV file.

ankits
  • 305
  • 1
  • 3
  • 13

2 Answers2

0

fackbook like count query:

Getting the Facebook like/share count for a given URL

twitter share count you can check this

Is there a way to get the twitter share count for a specific URL?

Community
  • 1
  • 1
vivia
  • 2,983
  • 1
  • 13
  • 8
-2

Since you're trying to only get the likes from the page. I suggest you use the graphAPI to get the likes and then convert that using Beautiful Soup and write it to a file the you can read the file to get your data. This is an example of a script I wrote to do the same.

import urllib2
from bs4 import BeautifulSoup 
x = urllib2.urlopen("https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27https://www.facebook.com/mitrevels?ref=br_tf%27")
soup = BeautifulSoup(x)
y = soup.get_text() 
f = open("write.txt","wr") 
f.write(y) 
f.close() 

This will just give me the likes on the particular page. All you need to do is change the url part to get the likes on your particular page. The same is available for twitter. Read the documentation to get the results.

StackUser2204
  • 126
  • 1
  • 6