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.