syed_iqbal
03-11-2017, 12:47 PM
Hi,
I'm new to web scraping. Now I trying to login into Gmail. After entering the password, the code is doing nothing (not opening Gmail account). Pls go through it and correct it.
Dim MyBrowser As InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
Sub MyGmail()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://www.gmail.com"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do While MyBrowser.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = MyBrowser.Document
Set HTMLInput = HTMLDoc.getElementById("Email")
HTMLInput.Value = "learningexcelvba@gmail.com"
Set HTMLButtons = HTMLDoc.getElementsByName("next")
HTMLButtons(0).Click
Set HTMLDoc = MyBrowser.Document
Set HTMLInput = HTMLDoc.getElementById("Passwd-hidden")
HTMLInput.Value = "excelvba"
Set HTMLButtons = HTMLDoc.getElementsById("signIn")
HTMLButtons(0).Click
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next[/COLOR]
End If
End Sub
Thank you in advance.
regards
shiva
I'm new to web scraping. Now I trying to login into Gmail. After entering the password, the code is doing nothing (not opening Gmail account). Pls go through it and correct it.
Dim MyBrowser As InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
Sub MyGmail()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://www.gmail.com"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do While MyBrowser.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = MyBrowser.Document
Set HTMLInput = HTMLDoc.getElementById("Email")
HTMLInput.Value = "learningexcelvba@gmail.com"
Set HTMLButtons = HTMLDoc.getElementsByName("next")
HTMLButtons(0).Click
Set HTMLDoc = MyBrowser.Document
Set HTMLInput = HTMLDoc.getElementById("Passwd-hidden")
HTMLInput.Value = "excelvba"
Set HTMLButtons = HTMLDoc.getElementsById("signIn")
HTMLButtons(0).Click
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next[/COLOR]
End If
End Sub
Thank you in advance.
regards
shiva