PDA

View Full Version : Login into website(FB for my case) using MSXML2.XMLHTTP with VBA



bennyys
06-22-2017, 07:43 PM
Hi,
Let me explain what is my goal and what are my problem on using excel VBA.

My Target:
From my phone record(call log record using super back up) I got list of mobile number.
What I am trying to do now is I will use all these number as input on facebook search.
If those number link with certain profile on FB (in other word FB searching result is not empty) then copy the profile link and paste to excel.
So at the and I will get someting like: phone number in column a and profile link in column B(if any).

My working step:
In the process of find the way to reach my goal, following is my working step
1.Provide excel macro for checking if the internet connection is available. If there is an internet connection then move to the next step, if no internet connection then stop the process.
2.macro for log in to facebook. on this part I classify the step in to 2 parts:
2.1 Log in using internet explorer object
or
2.2 log in using xmlhttp object.
3. if log in is success then the next step is macro for searching phone number in FB and if found something then copy the link address and paste it to excel.If nothing found then jump to the next phone number.Repeat step 3 until the last number on the list.
4. if all done then using excel macro to log out from FB

My Progress so far:
step 1. done
step 2.1 I got several macro and working fine during the test. here is the code

alternative 1


Sub WebLogin()
Dim a As String
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.navigate "url"
Do Until .readyState = 4
DoEvents
Loop
.document.all.Email.Value = "enter your full email address here"
.document.all.pass.Value = "enter your password here"
.document.forms(0).submit
End With
End Sub


alternative 2


Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub MyFB()

Dim MyHTML_Element As IHTMLElement
Dim myurl As String
On Error GoTo Err_Clear
myurl = "url"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate myurl
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.Email.Value = "email address" 'Enter your email id here
HTMLDoc.all.pass.Value = "password" 'Enter your password here
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next

Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub


alternative 3


Sub vbax_55399_facebook_login()

With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "url"
Do While .Busy And Not .readyState = 4
DoEvents
Loop
.document.all.Item("email").Value = "email address"
.document.all.Item("pass").Value = "password"
.document.all.Item("loginbutton").Click
End With
End Sub


Step 2.2 No luck yet on this part yet, I am still searching the simple way to do this that is why I need help on this forum.
I got a function during my search but try it with no luck. below is the function


Function PageAuthorized(ByVal strUrl As String, ByVal strUserId As String, ByVal strPwd As String) As Boolean
Dim strHtml As String
Dim objPat As Object
Dim lngLoop As Long
Const strPSoftLoginPageUrl As String = "url”"' I will change this part to facebook link and adjust the HTML tag accordingly
Const strPattern As String = "You are not authorized for this page."
With CreateObject(“MSXML2.XMLHTTP”)
.Open “post”, strPSoftLoginPageUrl, False
.setRequestHeader “Content - type”, “application / x - www - form - urlencoded”
.send "userid=" & strUserId & "&pwd=" & strPwd
.Open “get”, strUrl, False
.setRequestHeader “Content - type”, “application / x - www - form - urlencoded”
.send
strHtml = .responseText
End With
With CreateObject(“VBScript.Regexp”)
.Global = True
.ignoreCase = True
.Pattern = strPattern
Set objPat = .Execute(strHtml)
End With
PageAuthorized = (objPat.Count > 0)
End Function


step 3. Searching on FB using data from excel. I haven,t got any luck on this part.
step 4. Haven't reach up to this part but for log out using ie object I can modify the log in macro. for log out using xmlhttp I need help for this part.

Resume of my problem:
I need help from this forum to solve my problem on step:
2.2 log in using xmlhttp object(How to log in to web site in general and to FB in particular using xmlhttp object)
3. How do I use excel macro to search phone number on FB and if found profile then copy the link and paste it to excel.
4. How do I use excel to log out from web site(which is log in previously) especially using xmlhttp object.

Thank you in advance..

Regards,
Benny