2

Hi I have a list of Facebook Page urls

eg...
http://www.facebook.com/daftpunk
http://www.facebook.com/DavidGuetta
...

What's the best way to:

  • Check if these urls are actually for Facebook Pages and not Profiles

  • Collect details such as # of fans from these Pages

Help would be very much appreciated.

RadiantHex
  • 24,907
  • 47
  • 148
  • 244

4 Answers4

3

Without scraping any content (which is against Facebook's terms of service anyway):

  1. Extract the username part of the URL i.e. the bit after the www.facebook.com/
  2. Do an FQL query of the form select fan_count from page where username='michaeljackson'
  3. If a result is return, you know it's a Page and not a user's profile.

See the Page FQL table for other data you can retrieve in the same call.

Karl B
  • 1,597
  • 8
  • 9
2

use urllib2 or pyfacebook to fetch the content

use BeautifulSoup or lxml to parse it

use the re module (regular expressions) to extract content for your verification and data gathering

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
  • sorry still doesn't help me to get **# of fans** :( – RadiantHex Jan 20 '10 at 22:01
  • you have to extract that yourself. perhaps using regular expressions. updated the answer. – Corey Goldberg Jan 20 '10 at 22:52
  • ok, I found out how to get the # of fans, the field value is not referenced in the RESTful API you can check yourself here http://wiki.developers.facebook.com/index.php/Pages.getInfo#Response The fan_count is available in FQL queries instead. Are you proposing to scrape the url and therefore to mine for data with BeautifulSoup or lxml? – RadiantHex Jan 20 '10 at 23:03
1

The # of fans is in an a tag with the class 'FanManager'. you can use Beautiful Soup to get the contents of this a tag, and regular expressions to get the data from the string (ex: 1,000,000 fans) as an int or whatever you would like.

To see if the page exists, check some of the tags to see if you are on the 404 page.

GSto
  • 41,512
  • 37
  • 133
  • 184
0

You can use scrapy or BeautifulSoup to scrape the content.

Seb
  • 17,141
  • 7
  • 38
  • 27