Posts Calendar

February 2010
S M T W T F S
« Dec    
 123456
78910111213
14151617181920
21222324252627
28  

Archives






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”

  1. Hacking Facebook…Exposed!! « Charafantah’s cave Says:

    [...] can read here to know how to extract friends id’s from the friend’s page to a text(CSV) [...]

  2. testing Says:

    not working!

  3. charafantah Says:

    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 :)

  4. Steph Says:

    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.

  5. charafantah Says:

    hmm, try renaming the file as .html not just .htm
    i’ll check the code again soon… i forgot what extensions it was allowing :)

  6. k Says:

    I tried it but it wont give me any names or ids for a particular person - does it mean im on the blocked - llist?

  7. pat Says:

    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???

  8. Facebook ID extractor - Facebook Friends to CSV « Charafantah’s cave Says:

    [...] Facebook ID extractor [...]

  9. mark Says:

    IS THERE ANY NEW code out there since the last one was fix,, about seeing pictures etcc….

  10. Jay Says:

    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?

Leave a Reply