0

I'm trying to make access login in site and get some data from it that is my code :

Private Sub Command4_Click()

Dim i As SHDocVw.InternetExplorer
Dim ht As HTMLDocument

Set i = New InternetExplorer
i.Visible = True
i.navigate ("https://billing.te.eg/en-US")
Do While i.ReadyState <> READYSTATE_COMPLETE
Loop
Dim idoc As MSHTML.HTMLDocument
Set idoc = i.Document
idoc.all.TxtAreaCode.Value = "45"
idoc.all.TxtPhoneNumber.Value = "03824149"
Dim ele As MSHTML.IHTMLElement
Dim eles As MSHTML.IHTMLElementCollection
Set eles = idoc.getElementsByClassName("btn")
For Each ele In eles
   If ele.Type = "button" Then
      ele.Click
   Else
   End If
Next ele
Do While i.ReadyState <> READYSTATE_COMPLETE
Loop
If i.ReadyState = READYSTATE_COMPLETE Then
   Dim Doc As HTMLDocument
   Set Doc = i.Document
   Dim sdd As String
    sdd = Trim(Doc.getElementsByClassName("col-md-12").innerText)
   MsgBox sdd
Else: End If
End Sub

and this is the part that i need to get data , I need to know the idea of how to get data which doesn't have a class name or id such like that enter image description here

FaneDuru
  • 38,298
  • 4
  • 19
  • 27
ahmed403
  • 3
  • 3
  • 1
    I highly recommend NOT using InternetExplorer and using background http request objects instead: https://stackoverflow.com/questions/158633/how-can-i-send-an-http-post-request-to-a-server-from-excel-using-vba – jamheadart Jun 07 '20 at 18:40

1 Answers1

0

Try complying with the following approach. It is way faster than IE.

Sub FetchData()
    Const Url$ = "https://billing.te.eg/api/Account/Inquiry"
    Dim S$, elem As Object, payload As Variant
    Dim phone$, areaCode$, counter&

    counter = 1
    areaCode = "45"        'put areacode here
    phone = "03824149"     'put phone number here

    payload = "AreaCode=" & areaCode & "&PhoneNumber=" & phone & "&PinCode=&InquiryBy=telephone&AccountNo="

    Do
        With CreateObject("MSXML2.XMLHTTP")
            .Open "POST", Url, False
            .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
            .setRequestHeader "Referer", "https://billing.te.eg/en-US"
            .setRequestHeader "X-Requested-With", "XMLHttpRequest"
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
            .send payload
            S = .responseText
        End With

        With CreateObject("VBScript.RegExp")
            .Global = True
            .MultiLine = True
            .Pattern = "TotalAmount"":(.*?),"
            Set elem = .Execute(S)
            If elem.Count > 0 Then
                MsgBox elem(0).SubMatches(0)
                Exit Do
            End If
        End With

        counter = counter + 1
        If counter = 3 Then Exit Do
    Loop
End Sub
SIM
  • 21,997
  • 5
  • 37
  • 109
  • It's really weird that the script was required to run twice to get the results. However, I've created a loop to fix that. Thanks. – SIM Jun 07 '20 at 19:42
  • Wow That's worked very fast bro so, what should I learn to code like that ??? I only have some basic of vba and access – ahmed403 Jun 08 '20 at 04:13