Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Scraping Web data from a database platform (VBA - HTML)

$
0
0

I'm not good at developing but I need to complete this task for a small automation project. The situation is that i have to log in to a database and print out some data to excel, this for checking if data is deleted or not.

What do i want from the code?

By clicking on the macro button in Excel:

  • Log in into the site [x]
  • Search for a given number [x]
  • Print back in excel what the status is of the element []
  • Repeat from step 2 until there are numbers present in the column A (which loop?) []

https://imgur.com/u4IhpW7

As you can see in the excel screenshot under the cell A9 is where the numbers list will begin. Under the cell B9 is where i want my data printed out per each of the numbers on the left.

So I managed to Log in already and search for the first Number.

Here by the whole code:

Sub Login()

    Dim ie As New SHDocVw.InternetExplorer
    Dim HTMLDoc As MSHTML.HTMLDocument
    Dim HTMLInput As MSHTML.IHTMLElement

    ie.Visible = True

    ie.Navigate Sheet1.Range("B2").Text

    Do While ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
    Loop

    Set HTMLDoc = ie.Document

'Setting Username to a specific value
    Set HTMLInput = HTMLDoc.getElementById("ctl00_WebPartManager1_gwpLogin1_Login1_UserName")

    HTMLInput.Value = Sheet1.Range("B3")

'Setting Password to a specific value
    Set HTMLInput = HTMLDoc.getElementById("ctl00_WebPartManager1_gwpLogin1_Login1_Password")

    HTMLInput.Value = Sheet1.Range("B4")
'Click to login
    Set HTMLInput = HTMLDoc.getElementById("ctl00_WebPartManager1_gwpLogin1_Login1_LoginButton")

    HTMLInput.Click

    MsgBox ("Login Succesfull")

    While ie.Busy
        DoEvents
    Wend

    Set HTMLInput = HTMLDoc.getElementById("ctl00_SearchSection_ObjectSearch_txtEMail")
    HTMLInput.Value = Null

    Set HTMLInput = HTMLDoc.getElementById("ctl00_SearchSection_ObjectSearch_txtCustomerID")
    HTMLInput.Value = Sheet1.Range("A10")

    Set HTMLInput = HTMLDoc.getElementById("ctl00_SearchSection_ObjectSearch_SearchButton")
    HTMLInput.Click

    While ie.Busy
        DoEvents
    Wend
'On Error Resume Next
End Sub

The second part might be not correct, but that's how i managed to search for that given number. I have to figure out how to loop until are numbers present in column A starting from A9.

This is how the site look like

https://imgur.com/4GJQ4oF

So what i need to print in column B starting from B9 is the innerText of 'Status'. There is a condition to be met as well and that is if the innertext of status is 'Deleted' but the innerText of 'Name' is not empty then print Error in column B.

So the table in question has tags with no ID so i don't know how to manipulate them. Another thing to mention is that if the fields are empty the innerText is shown as :

&nbsp ;

Thanks in advance for any help and the attention to read all of this.

Greetings,

Alessio


Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>