How to automate the login in a web

2

I have a problem that I have not yet found the solution, I recently registered on a website and I set out to create an automatic login with excel macros. Everything seems to work, but I can not fill in the requested fields and therefore does not log in.

this is the code that I used:

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer

 Sub auto_open()

 Dim MyHTML_Element As IHTMLElement
 Dim MyURL As String
 On Error GoTo Err_Clear
 MyURL = "https://www.presearch.org/login"
 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 = "mi email" 'Aqui pongo mi email de login
 HTMLDoc.all.passwd.Value = "mi contraseña" 'Aqui pongo mi contraseña
 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

Thanks for your help!

    
asked by Jensyr 23.12.2018 в 15:06
source

1 answer

1

use a css attribute selector

Option Explicit
Public Sub detalles()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True

        .Navigate2 "https://www.presearch.org/login"

        While .Busy Or .readyState < 4: DoEvents: Wend

        With .document
            .querySelector("[type=email]").Value = "[email protected]"
            .querySelector("[type=password]").Value = "contrasena"
            .querySelector(".form-group [type=submit]").Click
        End With

        While .Busy Or .readyState < 4: DoEvents: Wend
        '****************
        Stop
        '****************
    End With
End Sub
    
answered by 23.12.2018 / 20:04
source