Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Web Scraping Login

  1. #1
    New Member
    Join Date
    Jun 2018
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Web Scraping Login

    I am going nuts trying to figure this out!

    I am needing to navigate to a site and login through VBA to scrap some data. (which I have done several times before)

    I cannot for the life of me figure out the HTML for this particular site.

    https://www.e-oscar-web.net/EntryCon...?trigger=Login

    Any help is greatly appreciated.

    Thank you!

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,855
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Web Scraping Login Help!!!

    Try the following macro...

    Code:
    Option Explicit
    
    Sub E_Oscar_Login()
    
    
        Dim ie As Object
        Dim doc As Object
        
        Const READYSTATE_COMPLETE As Long = 4
        
        Set ie = CreateObject("InternetExplorer.Application")
        
        With ie
            .Visible = True
            .navigate "https://www.e-oscar-web.net/EntryController?trigger=Login"
            Do While .Busy Or .readyState <> READYSTATE_COMPLETE
                DoEvents
            Loop
        End With
        
        Set doc = ie.document
        
        With doc
            .querySelector("#companyId").Value = "12345"
            .querySelector("#userId").Value = "XYZ"
            .querySelector("#password").Value = "123"
        End With
        
        doc.querySelector("[value='Login']").Click
        
        Set ie = Nothing
        Set doc = Nothing
        
    End Sub
    Hope this helps!

  3. #3
    New Member
    Join Date
    Jun 2018
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Web Scraping Login Help!!!

    Quote Originally Posted by Domenic View Post
    Try the following macro...

    Code:
    Option Explicit
    
    Sub E_Oscar_Login()
    
    
        Dim ie As Object
        Dim doc As Object
        
        Const READYSTATE_COMPLETE As Long = 4
        
        Set ie = CreateObject("InternetExplorer.Application")
        
        With ie
            .Visible = True
            .navigate "https://www.e-oscar-web.net/EntryController?trigger=Login"
            Do While .Busy Or .readyState <> READYSTATE_COMPLETE
                DoEvents
            Loop
        End With
        
        Set doc = ie.document
        
        With doc
            .querySelector("#companyId").Value = "12345"
            .querySelector("#userId").Value = "XYZ"
            .querySelector("#password").Value = "123"
        End With
        
        doc.querySelector("[value='Login']").Click
        
        Set ie = Nothing
        Set doc = Nothing
        
    End Sub
    Hope this helps!
    Thank you for the help! I am now stuck trying to click on part of the header. The HTML code is below.

    Archive



    Thank you!
    Last edited by scotsrule08; Aug 7th, 2019 at 07:51 PM.

  4. #4
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,855
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Web Scraping Login Help!!!

    Sorry, which part of the header are you talking about? There's no HTML code below.

  5. #5
    New Member
    Join Date
    Jun 2018
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Web Scraping Login Help!!!

    Quote Originally Posted by Domenic View Post
    Sorry, which part of the header are you talking about? There's no HTML code below.

    class="InactiveTabLink" id="Archiveanch" *******='javascr
    ipt:left("", "Archive", "LeftReq", "RefreshView?trigger=Opti
    onsPageProcess");return false;' href="#">Archive

  6. #6
    New Member
    Join Date
    Jun 2018
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Web Scraping Login Help!!!

    Sorry, for some reason when I used the code tags it took the code as a link. Any help is appreciated! Thank you!

  7. #7
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,855
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Web Scraping Login Help!!!

    In that case, once the login button is clicked, you should wait until the new page loads, then you should assign the new document to the object variable doc, and then you can click on your target element.

    Code:
    Option Explicit
    
    Sub E_Oscar_Login()
    
    
        Dim ie As Object
        Dim doc As Object
        
        Const READYSTATE_COMPLETE As Long = 4
        
        Set ie = CreateObject("InternetExplorer.Application")
        
        With ie
            .Visible = True
            .navigate "https://www.e-oscar-web.net/EntryController?trigger=Login"
            Do While .Busy Or .readyState <> READYSTATE_COMPLETE
                DoEvents
            Loop
        End With
        
        Set doc = ie.document
        
        With doc
            .querySelector("#companyId").Value = "12345"
            .querySelector("#userId").Value = "XYZ"
            .querySelector("#password").Value = "123"
        End With
        
        doc.querySelector("[value='Login']").Click
        
        With ie
            Do While .Busy Or .readyState <> READYSTATE_COMPLETE
                DoEvents
            Loop
        End With
        
        Set doc = ie.document
        
        doc.querySelector("#Archiveanch").Click
        
        Set ie = Nothing
        Set doc = Nothing
        
    End Sub

  8. #8
    New Member
    Join Date
    Jun 2018
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Web Scraping Login Help!!!

    Thank you for the response. I am getting Runtime error 424 object required pointing to line "doc.querySelector("#Archiveanch").Click "

    Thank you!

  9. #9
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,855
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Web Scraping Login Help!!!

    I understood the id to be Archiveanch. Is this correct? Any spelling mistakes?

    If the id is correct, maybe the new page hasn't fully finished loading. Try stepping slowly through the code by pressing F8. Does this help?

  10. #10
    New Member
    Join Date
    Jun 2018
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Re: Web Scraping Login Help!!!

    Quote Originally Posted by Domenic View Post
    I understood the id to be Archiveanch. Is this correct? Any spelling mistakes?

    If the id is correct, maybe the new page hasn't fully finished loading. Try stepping slowly through the code by pressing F8. Does this help?

    I copied and pasted directly from the DOM. I double checked and it is all spelled correctly. I also stepped through the code (using F8) and also added a wait time of 8 seconds to ensure the page was loaded fully. I still received the same 424 error.

    Thank you!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •