Christoffer's posterous

Christoffer's posterous

Christoffer Torris Olsen  //  The sideshow of my life: Quirks I've ironed out while coding that I might use in the future. And here they are for you to use as well.

Jan 12 / 8:46am

Python Script: Export a list of Facebook Fans for a Page to CSV

Click here to download:
facebookfans.py (5 KB)

I made a primitive script to export a list of Facebook fans for a Page.

It's somewhat cumbersome to use, as you need to hand it some HTTP headers such as your cookie. Instructions are in the script. If someone has an easier way of doing this, please let me know :-)

The files open nicely in Numbers on Mac, nothing else is tested.

Thanks to Adam Loving for the inspiration and original codebase.

14 comments

Feb 17, 2010
Ofer said...
You probably see this question funny , but can you explain how to run this scrip ?
Apr 10, 2010
william said...
great post ! nice script, it works for me :) thanks ~! save me lots of time on this ... thanks Adam Loving !!
Apr 29, 2010
 said...
Looks good.. but I ran into an issue and hope you can help. I replace <pageid> with my page name? or do i need the actual number code for it.

I updated the header information in the python script and when I try to run it, I get this error:

[root@gold httpdocs]# python facebookfans.py <pageid> fans.csv
In page 0
Traceback (most recent call last):
File "facebookfans.py", line 167, in ?
fans_list = fetch_fans(sys.argv[1])
File "facebookfans.py", line 70, in fetch_fans
li = [k for k in fans['payload']['user_info']]
TypeError: unsubscriptable object

Apr 29, 2010
 said...
update: i found my facebook page ID and when I run the script now I get these errors:

In page 0
Traceback (most recent call last):
File "facebookfans.py", line 167, in ?
fans_list = fetch_fans(sys.argv[1])
File "facebookfans.py", line 67, in fetch_fans
page = get_page(page_count, page_id)
File "facebookfans.py", line 49, in get_page
response = urllib2.urlopen(req)
File "/usr/lib64/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib64/python2.4/urllib2.py", line 358, in open
response = self._open(req, data)
File "/usr/lib64/python2.4/urllib2.py", line 376, in _open
'_open', req)
File "/usr/lib64/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
File "/usr/lib64/python2.4/urllib2.py", line 1032, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib64/python2.4/urllib2.py", line 1004, in do_open
r = h.getresponse()
File "/usr/lib64/python2.4/httplib.py", line 872, in getresponse
response.begin()
File "/usr/lib64/python2.4/httplib.py", line 336, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python2.4/httplib.py", line 300, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine

Aug 10, 2010
B said...
Yes, I'm having a similar error message. Please help. Thanks.
Oct 11, 2010
 said...
Thank you so much for this! I had to hack around a bit, but it works. I was able to get all the information I needed using the Live HTTP Headers firefox extension, so I didn't have to figure out a tool like Wireshark.
Oct 12, 2010
 said...
Hey Ross - I'm getting a response, but not seeing the payload with the fans - what exactly did you hack around? Thanks!
Dec 07, 2010
Chris:
Can I pay you to do this for me?
john.wayne.zimmerman @ gmail dot com

Thanks.

Dec 08, 2010
Alex said...
Hi Chris. I'm not able to find the 'data' variable among the HTTP headers. Any idea?
Jan 04, 2011
Hi guys,

Thanks for the feedback. Sorry I haven't been able to update the script. I'm guessing FB has changed things around a bit. I don't have time to fix it at the moment, unfortunately :(

John: I might be able to help you – you could send me an email at chris@ctolsen.no if you're still interested.

Apr 20, 2011
Houseof Humility said...
Hi mate,

i am a major noob... but i am from a marketing company that overseas 5 facebook fan pages that total over 250,000 fans.

can i pay you to extract these to csv./excel file...??

my email is humilityclothing@hotmail.com

let me know asap,

cheers,

Jim

May 09, 2011
Jun 17, 2011
vcgs said...
Hi all.

A new version of fbPageMembers includes Magic Importer to automatically import the fans.

Please, take a tour to http://www.fbpagemembers.com/ and read the documentation to know how fbPageMembers works....

Thanks!

Oct 19, 2011
maury19 said...
Facebook fan page is an excellent way to get fans coming back for more. Create a Contest tab where you can run monthly contests for your fans. Give away something small to the winners and make the contests fun. Consider redesigning your Contest tab often to keep it fresh and to match each individual contest. This will make for a well rounded and fun user experience.This highly interactive practice means you are not only gathering valuable information for your company, but you are creating a Facebook community. For example, say you are a company that focuses on a product for kids.

Get Fans on Facebook

Leave a comment...