This entry was posted on Monday, November 12th, 2007 at 11:11 am and is filed under Security, Technology, fun. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Facebook ID extractor - Facebook Friends to CSV
5 Jan 2008 Update: I found an application that does the same function on facebook, it can be found here, i have not tried it though and am not sure it provide the same functionality, but you can try
I wrote a small shell script in Bash and PHP, that takes the friends page from facebook and extracts the ID and names into a CSV file.
It could be useful to keep track of your friends and\or save a backup.
Or you could combine that with the “Hacking Facebook…Exposed” post and try to improvise with your own tricks
It could also be used as a reference, in case you want to check if someone blocked you, or deactivated their account (you can read here to check how to find if someone blocked you or deactivated their account)
- Open your facebook account
- Navigate to http://www.facebook.com/friends.php , make sure there is nothing after friends.php
- Save the page as HTML
- Copy\paste the code below to a text file (let’s call it fbf2csv.sh)
- Then chmod it (chmod 755 fbf2csv.sh)
- Then execute it (./fbf2csv.sh Friends.html output.csv)
#!/bin/bash echo 'Facebook Friends ID and Name extractor a.k.a FBF2CSV by Achraf El Kashef (Charafantah) http:\\charafantah.wordpress.com\ 11 Nov 2007 ' if [ $# -ne 2 ]; then echo 1>&2 Usage: $0 friends.php.html output.txt exit 1 fi grep profile.php $1 | \ grep .jpg | \ grep -v sidebar | \ grep -oE 'id=[0-9]*&*[[:alpha:]]*;*[[:alpha:]]*">*[[:alpha:] -.]*</' | \ sed 's/id=//' | \ sed 's/">/,"/' | \ sed 's/<\//"/' | \ sed 's/&highlight//' > $2 cat $2 exit 0
I wrote this in 15 mins, so don’t complain about the code or tell me the regex could have been written in a better way(i suck at regex anyway)
Am going today to write this into a PHP script, and publish it online, should make it easier for people with no access to linux or cygwin.
You can get it here now: http://www.misr2000online.net/facebook/
If you can provide a better host for the php script (a decent one) please contact me.
Currently, the script will support names with the following:
- Multiple spaces in the name (e.g. John Doe Foo Bar)
- Dashes (e.g. John Foo-Bar)
- Single quotes (e.g. John Fo’ Bar)
- Dots (e.g. John F. Bar)
It will not support non Latin characters (e.g. accented characters like french é ê or anything like that, any entry like this will just be discarded,, you can however change the regex (on line 8 from bottom) to make it parse only the ID# and discard all the names) (anyone know how can i match these in regex?)
Please give me feed back if it doesn’t work as expected with you, i haven’t tested it on other lists than mine, but i expect it should work as fine.
10 Responses to “Facebook ID extractor - Facebook Friends to CSV”
Leave a Reply

November 14th, 2007 at 12:46 pm
[...] can read here to know how to extract friends id’s from the friend’s page to a text(CSV) [...]
December 6th, 2007 at 4:56 pm
not working!
December 6th, 2007 at 5:09 pm
well, am sorry, as i said it has been written in 15 mins and was not tested on other accounts than mine, so yes
i expect it to have some bugs.
can you please email me what happened exactly and if you can send me a copy of the file you tried to parse on my email.
and i will try my best to fix it
thanks
December 19th, 2007 at 9:55 pm
I seem to have saved the file as a .htm (saved as Save HTML) and the program you have won’t take the file? It says it’s the wrong extention.
December 20th, 2007 at 2:58 am
hmm, try renaming the file as .html not just .htm
i’ll check the code again soon… i forgot what extensions it was allowing
January 31st, 2008 at 6:05 am
I tried it but it wont give me any names or ids for a particular person - does it mean im on the blocked - llist?
February 2nd, 2008 at 2:43 pm
Im looking for a way to actually extract the login email adresses of my friends and othyer users on FB - For example aspecific group; friends and non friends… Is this possible???
April 7th, 2008 at 11:56 pm
[...] Facebook ID extractor [...]
April 12th, 2008 at 2:35 am
IS THERE ANY NEW code out there since the last one was fix,, about seeing pictures etcc….
April 26th, 2008 at 12:50 am
Hey I used the bigsight app, but all it gives me is the same stuff on the friends list in text format. And how can i do the above process on a mac?