1

I've been hours searching different ways to login into a web for scraping purposes but I just can't find the way. The last thing I tried is following this topic but still no success....

This is my code:

Option Explicit
Sub DescargaInformes()


    Dim ieApp As InternetExplorer
    Dim ieDoc As Object
    Dim ieTable As Object
    Dim clip As DataObject
    Dim oHTML_Element As Object

    'creamos nueva instancia del IE y vamos a la web
    Set ieApp = New InternetExplorer
    With ieApp
        .Navigate "https://mediamarkt.zendesk.com/access/unauthenticated"
        .Visible = True
    End With

    'esperamos a que la web esté cargada
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    Set ieDoc = ieApp.Document

    'rellnamos los datos de login y pass
    With ieDoc
        .getElementById("user_email").Value = "user"
        .getElementById("user_password").Value = "pass"
    End With

    'esperamos a que la web esté cargada
    Do While ieApp.Busy: DoEvents: Loop
    Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

    Set ieDoc = ieApp.Document

End Sub

Can someone point me in the right direction on how to login here?

This is (what I think) the code that show's the user and pass id's:

<div class="credentials">
              <label for="user_email">Correo electrónico</label>
              <input name="user[email]" id="user_email" autofocus="autofocus" type="email" autocomplete="on">
              <label for="user_password">Contraseña</label>
              <input name="user[password]" id="user_password" type="password" autocomplete="off">
            </div>

Edit: I get the error here .getElementById("user_email").Value = "user" object required.

QHarr
  • 83,427
  • 12
  • 54
  • 101
Damian
  • 5,152
  • 1
  • 10
  • 21

1 Answers1

1

It is inside an iframe so either negotiate that or use the iframe src direct

Direct:

Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls

Public Sub Login()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate2 "https://mediamarkt.zendesk.com/auth/v2/login/signin?return_to=https%3A%2F%2Fmediamarkt.zendesk.com%2F&theme=hc&locale=1&brand_id=2726349&auth_origin=2726349%2Cfalse%2Ctrue"

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

        With .document
            .querySelector("#user_email").Value = "joe.bloggs@hotmail.com"
            .querySelector("#user_password").Value = "abcde"
            .querySelector("[value='Sign in']").Click
        End With

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

        Stop

        .Quit
    End With
End Sub

Negotiating iframe:

Option Explicit
'VBE > Tools > References: Microsoft Internet Controls
Public Sub Login()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate2 "https://mediamarkt.zendesk.com/access/unauthenticated"

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

        With .document.getElementsByTagName("iframe")(0).contentDocument
            .querySelector("#user_email").Value = "joe.bloggs@hotmail.com"
            .querySelector("#user_password").Value = "abcde"
            .querySelector("[value='Sign in']").Click
        End With

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

        Stop

        .Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • Amazing Qharr! Also... if like me, you are not a programmer it's going to be hard to find something like this, right? Also... Could I do a xmlhttprequest in this web? Should be fair easier I think. – Damian May 21 '19 at 20:35
  • Not hard really. You just need to learn a little html. If you know your selector is correct but you get the error you got it usually means 1 of 2 things: 1) timing - trying to access before present 2) element within a frame or iframe. You can check for the latter by examining the html and seeing if there is a parent iframe tag. With respect to xmlhttp - depends if site allows for authentication via that route. Again - you will get some idea about that if there is a form and an associated xhr request in the network tab (dev tools) when you manually login. A little practice you’ll find it easy. – QHarr May 21 '19 at 20:52
  • 1
    Thank you QHarr, I believe I can use the xml way since I saw sniffing the requests that there are a lot of GET-POST (and I think this is the way xml requests work) – Damian May 21 '19 at 21:04