Welcome to FreeSoftwareServers Confluence Wiki

Sub Test()

'tr = Table Tr
'td = Table Data (Cell Data)

 Dim URLStr As String
 URLStr = "https://pokemondb.net/pokedex/all"
 
 Dim TableIdStr As String
 TableIdStr = "pokedex"
 
 Call OPENIEURL(URLStr, False)
 
 Dim table As MSHTML.HTMLTable
 Set table = IEObj.document.getElementById(TableIdStr)

 Dim RowFoundElmObj  As MSHTML.HTMLGenericElement, RowUniqueKeyStr As String
 RowUniqueKeyStr = "Charmander"
 Set RowFoundElmObj = Get_HTMLTableRow(RowUniqueKeyStr)
 'Stop
 
 Dim RowFoundDataElmObj As MSHTML.HTMLGenericElement, RowDataUniqueKeyStr As String
 RowDataUniqueKeyStr = "total"
 Set RowFoundDataElmObj = Get_HTMLTableRowData(RowFoundElmObj, RowDataUniqueKeyStr)
 'Stop
 
 
 Debug.Print "RowFoundDataElmObj.innerText = " & RowFoundDataElmObj.innerText
 Debug.Print "RowFoundDataElmObj.outerText = " & RowFoundDataElmObj.outerText
 Debug.Print "RowFoundDataElmObj.innerHTML = " & RowFoundDataElmObj.innerHTML
 Debug.Print "RowFoundDataElmObj.outerHTML = " & RowFoundDataElmObj.outerHTML
 'Stop
End Sub
Public Function Get_HTMLTableRow(ByVal RowUniqueKeyStr As String) As MSHTML.HTMLGenericElement ' Should ByVal Doc
 Dim TRHTMLColl As MSHTML.IHTMLElementCollection
 Dim TRElmObj As MSHTML.HTMLGenericElement
 Set TRHTMLColl = IEObj.document.getElementsByTagName("tr")
 For Each TRElmObj In TRHTMLColl
   'Stop
   If InStr(TRElmObj.innerText, RowUniqueKeyStr) > 0 Then
    Set Get_HTMLTableRow = TRElmObj
    'Stop
    'Debug.Print "TRElmObj.innerText = " & TRElmObj.innerText
    'Debug.Print "TRElmObj.outerText = " & TRElmObj.outerText
    'Debug.Print "TRElmObj.innerHTML = " & TRElmObj.innerHTML
    'Debug.Print "TRElmObj.outerHTML = " & TRElmObj.outerHTML
    'Stop
    Exit Function
   End If
   'Debug.Print "TRElmObj.innerText = " & TRElmObj.innerText
   'Debug.Print "TRElmObj.outerText = " & TRElmObj.outerText
   'Debug.Print "TRElmObj.innerHTML = " & TRElmObj.innerHTML
   'Debug.Print "TRElmObj.outerHTML = " & TRElmObj.outerHTML
 Next TRElmObj
End Function
Public Function Get_HTMLTableRowData(ByVal RowFoundElmObj As MSHTML.HTMLGenericElement, RowDataUniqueKeyStr As String) As MSHTML.HTMLGenericElement ' Should ByVal Doc and HTMLTableCell
 Dim TDElmObj As MSHTML.HTMLGenericElement
 Set TDHTMLColl = RowFoundElmObj.getElementsByTagName("td")
 Debug.Print RowFoundElmObj.getElementsByTagName("td")(3).innerText
 'Stop
 For Each TDElmObj In TDHTMLColl
   'Stop
  If InStr(TDElmObj.innerText, RowDataUniqueKeyStr) > 0 Or InStr(TDElmObj.outerHTML, RowDataUniqueKeyStr) > 0 Then
   Set Get_HTMLTableRowData = TDElmObj
   'Stop
   'Debug.Print "TDElmObj.innerText = " & TDElmObj.innerText
   'Debug.Print "TDElmObj.outerText = " & TDElmObj.outerText
   'Debug.Print "TDElmObj.innerHTML = " & TDElmObj.innerHTML
   'Debug.Print "TDElmObj.outerHTML = " & TDElmObj.outerHTML
   'Stop
   Exit Function
  End If
  'Debug.Print "TDElmObj.innerText = " & TDElmObj.innerText
  'Debug.Print "TDElmObj.outerText = " & TDElmObj.outerText
  'Debug.Print "TDElmObj.innerHTML = " & TDElmObj.innerHTML
  'Debug.Print "TDElmObj.outerHTML = " & TDElmObj.outerHTML
  'Stop
 Next TDElmObj
End Function
  • No labels