Jump to content

Simpe Facebook Friends 'Screen Scraper'


Szhlopp
 Share

Recommended Posts

Hey guys,

I was PM'ed about how to get a list of friends off of facebook. I developed a couple of sample UDF's on how to do that as well as a few functions to get information (like a phone number or email address).

What you need to know:

1) I am requiring you to be on the persons friends page (navigate to your/their profile and click the 'Friends (100)' link on the left hand column). If you want to automate this, it's as simple as adding a line to navigate to it everytime.

2) For speed, you may want to store the list you get someplace and work off of it instead of loading it everytime (load takes about 20sec - 1 minute depending on friends list size)

3) this is a sample UDF. If you have questions feel free to ask, but I am not advertising a finished product here :)

Enjoy!

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Szhlopp

 Script Function:
    Simple facebook friends 'screen scraper'.
    This is mostly an example set of UDF's that you can easily expand upon.

#ce ----------------------------------------------------------------------------

#include "IE.au3"
#include <Array.au3>
;
;




; YOU need to make sure you're logged in.
$oIE = _IEAttach("facebook", "URL")


;Get the array
$FriendsArray = FBGetFriends($oIE)

;Count the number of friends
MsgBox(0, "", "Number of friends: " & UBound($FriendsArray) / 2)

;Get their UID by name
MsgBox(0, "", FBGetUIDByName($FriendsArray, "Bob Smith"))

; Navigate to a persons info page to scrape a number or email addresses
_IENavigate($oIE, FBBuildFriendsInfoURL(FBGetUIDByName($FriendsArray, "Bob Smith")))
FBGetEmailAddresses($oIE) ; MUST be on info page
FBGetPhoneNumber($oIE) ; MUST be on info page



; returns an array of [n] UID [n + 1] Name
Func FBGetFriends($oIE)

    $FriendsCount = 0

    If StringInStr(_IEPropertyGet($oIE, "locationurl"), "friends") >= 1 Then

        $pass = 1
        $scrollmore = True

        while $scrollmore = True
            $CurrCount = _FBGetFriendsCount($oIE)

            If $CurrCount = $FriendsCount Then
                $pass += 1
                If _FBCheckFullList($oIE) = 1 Then
                    $oIE.document.parentwindow.scroll(0, 0)
                EndIf

            Else
                $pass = 1
            EndIf

            $FriendsCount = $CurrCount

            $oIE.document.parentwindow.scroll(0, 900000)

            Sleep(250)

            If $pass >= 5 then $scrollmore = False

        WEnd

        $SRE = StringRegExp(_IEBodyReadHTML($oIE), '(?i)eng\_tid\"\:(\d*)\,\"eng\_data\"\:\[\]\}\}\' & "'\>([^\<].*?)\<", 3) ;(?i)eng\_tid\"\:(\d*)\,\"eng\_data\"\:\[\]\}\}\'\>([^\<].*?)\<
        Return $SRE

    Else
        MsgBox(0, "", "Please load up facebook, go to the persons facebook page and click 'Friends (100)' on the left hand side")
    EndIf

EndFunc

; Returns the navigation url to a friends info page
Func FBBuildFriendsInfoURL($ID)
    Return "facebook.com/profile.php?id=" & $ID & "&sk=info"
EndFunc

; Returns an array of phone numbers
Func FBGetPhoneNumber($oIE)
    $SRE = StringRegExp(_IEBodyReadHTML($oIE), "(?i)phone.*?uiListVertical.*?\>(.*?)\<SPAN", 3)
    Return $SRE
EndFunc

; Returns an array of address
Func FBGetEmailAddresses($oIE)
    $SRE = StringRegExp(_IEBodyReadHTML($oIE), '(?i)LI\sclass\=\"uiListItem\s\s?\s?uiListVerticalItemBorder\"\>([^\<].*?)\<\/LI', 3)
    Return $SRE
EndFunc

; returns the UID
Func FBGetUIDByName($aFriendsArray, $sFriendsName)
    $index = _ArraySearch($aFriendsArray, $sFriendsName)
    Return $aFriendsArray[$index - 1]
EndFunc


;Internal
func _FBCheckFullList($oIE)

    $oLinks = _IELinkGetCollection($oIE)
    for $link in $oLinks
        if StringInStr($link.outerText, "see more") >= 1 and StringInStr($link.href, "list/friends/all") >= 1 then
            Return 1
        EndIf

    Next

    Return 0

EndFunc


func _FBGetFriendsCount($oIE)
    $SRE = StringRegExp(_IEBodyReadHTML($oIE), '(?i)eng\_data\"' & "\:\[\]\}\}\'" & '\>([^\<].*?)\<', 3)
    Return UBound($SRE)
EndFunc
Link to comment
Share on other sites

it finds the amount the gives an error

Line 102

Return $aFrriendsArray[$index - 1]

Return $aFrriendsArray[^ ERROR

Error: Array variable subscript badly formatted

Can what it finds be exported to a txt file?

Link to comment
Share on other sites

it finds the amount the gives an error

Line 102

Return $aFrriendsArray[$index - 1]

Return $aFrriendsArray[^ ERROR

Error: Array variable subscript badly formatted

Can what it finds be exported to a txt file?

Line 102 "$index = _ArraySearch($aFriendsArray, $sFriendsName)", $sFriendsName must contain the name of a friend in the list.

For example if you are on your facebook name, you should not have it contain "Chimaera" because you are not in the list of friends. So if you have substituted "Bob Smith" for your own facebook name, you did it wrong, that needs to be a name from the list.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

im following exactly as suggested

I load up FB in IE

then click one of my friends and then click on their Friends 269 link which shows me all the friends they have.

run the script which makes the page jump around a bit whilst its working it then shows a message box saying 269 friends then

It throws the error

funnily enough it dosent work at all when i try it on my friends list but it does do something upto the error on other peoples

Link to comment
Share on other sites

Sorry guys, Should have made that more clear.

This is NOT error proofed and none of the data is being checked (validated). This is simply an example of how to do this. Yes, it is a working 'example UDF(user defined function)', meaning the calls inside are meant to be modified to fit your needs =) Hope that clears up the issues.

Szh

Link to comment
Share on other sites

I'm not sure what I am doing wrong, as I cannot seem to get this working.

I changed Bob Smith to one of my friend's names and complied it. I put the executable on the desktop.

Then went to my Facebook profile and clicked on Friends (n)

With IE8 in windowed mode, I double click on the executable on the desktop.

Then I get the message box saying that I have zero friends (thanks) and then this error message:

---------------------------

AutoIt Error

---------------------------

Line 3337 (File "C:\Users\Jason\Desktop\Facebook Friends Scraper.exe"):

Error: Subscript used with non-Array variable.

---------------------------

OK

---------------------------

What am I doing wrong? Posted Image

Link to comment
Share on other sites

Just a suggestion, but maybe you could use Facebook's API and create a simple app, and then use a free web host to host the app code, and then use autoit to rip the firends list from your site.

If you're interested in trying it, here's a link to get you started : http://developers.facebook.com/docs/reference/api/FriendList/

Peace.

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...