Jump to content

How to get text from IE Webpage?


jmp
 Share

Recommended Posts

table.PNG.4ec3f7b45c8e714c0c8ec460ad7eb836.PNG

 

I want to retrieve DateTime and User ID one by one and display them in a MsgBox.

Firstly, I would like to create an input box for SrNo. If I enter '1' in the input box, the first row of DateTime will be displayed in a MsgBox, followed by the User ID. Then, it should proceed to display the DateTime and User ID of the subsequent rows.

If I enter '2' or '3' in the Input box, the loop should start with the 2nd or 3rd row, respectively

 

<tr class="web-row-style">
            <td>1</td>
            <td>24/12/2023 09:33:21</td>
            <td>55801</td>    
        </tr>


<tr class="web-alternating-row">
            <td>2</td>
            <td>24/12/2023 08:51:30</td>
            <td>48887</td>
        </tr>

<tr class="web-row-style">
            <td>3</td>
            <td>23/12/2023 10:51:32</td>
            <td>289261</td>    
        </tr>

 

I have tried this: 

#include <IE.au3>

$oIE = _IEAttach ("Home")

Local $date
Local $oTds = _IETagNameGetCollection($oIE, "tr")
For $oTd In $oTds
    If $oTd.className = "web-row-style" Then
        $idate = $oTd.NextElementSibling.InnerText
        ExitLoop
    EndIf
Next

MsgBox(0, "your date is", $idate)

 

Link to comment
Share on other sites

1 minute ago, mikell said:

Personally I'd rather try something like this

Local $oTds = _IETableGetCollection($oIE)
For $oTd In $oTds
    $table = _IETableWriteToArray($oTd)
    _ArrayDisplay($table)
Next

and get a 2D array to work with

@mikell

I tried this code for it:

$oIE = _IEAttach ("Home")
$srno = 37

If StringInStr(_IEBodyReadHTML($oIE), "Member Quantity ") Then
Local $otable = _IEGetObjById($oIE, "Content")
Local $idate
Local $oTds, $oTrs = _IETagNameGetCollection($oIE, "tr")
If IsObj($oTrs) Then
    For $i = 1 To $oTrs.Length
        $oTr = $oTrs($i)
        $oTds = _IETagNameGetCollection($oTr, "td")
        If IsObj($oTds) And $oTds.Length = 3 Then
            $idate = $oTds(1).InnerText
            MsgBox(0, "your date is", $idate)
        EndIf
        Next

EndIf
EndIf

Its working, But i want to get DateTime by User ID. So please help

Link to comment
Share on other sites

10 minutes ago, mikell said:

Exactly what I meant. Using  _IETableWriteToArray  you get a 2D array which contains DateTime and the corresponding User ID on the same rows

@mikellNow, I don't need whole table.

I want to get only DateTime by entering User ID in Clipget

Edited by jmp
Link to comment
Share on other sites

@Nine, @mikell

$oIE = _IEAttach ("Home")


If StringInStr(_IEBodyReadHTML($oIE), "Member Quantity  ") Then
    Local $otable = _IEGetObjById($oIE, "Content")
    Local $idate
   Local $oTds, $oTrs = _IETagNameGetCollection($oIE, "tr")
    If IsObj($oTrs) Then
        $searchUserID = ClipGet() ; Get the user ID from the clipboard
        For $i = 0 To $oTrs.length - 1
            $oTr = $oTrs($i)
            $oTds = _IETagNameGetCollection($oTr, "td")
            If IsObj($oTds) And $oTds.length = 3 Then
                $currentUserID = $oTds(2).InnerText ; Assuming the user ID is in the third column (index 2)
                If $currentUserID = $searchUserID Then
                    $idate = $oTds(1).InnerText
                    MsgBox(0, "Date and Time for User ID " & $searchUserID, $idate)
                    ExitLoop ; Found the user ID, exit loop
                EndIf
            EndIf
        Next
    EndIf

I have created the above code, this code is working but it is showing results very slow. So, any idea about it?

Link to comment
Share on other sites

@mikell

This code is working for me. So this will be get accurate DateTime everytime?

Local $sUserId = ClipGet()
If @error Then Exit

; Check if the entered input is a 5-digit number
If StringRegExp($sUserId, "^\d{5}$") Then
    Local $oTable = _IETagNameGetCollection($oIE, "table")
    Local $bFound = False

    For $oRow In $oTable
        If StringInStr($oRow.outerHTML, "<td>" & $sUserId & "</td>") Then
            Local $oCells = $oRow.getElementsByTagName("td")
            For $i = 0 To $oCells.length - 1
                If $oCells.item($i).innerText = $sUserId Then
                    Local $sDateTime = $oCells.item($i - 1).innerText ; Assuming DateTime is in the column preceding the User ID column
                    MsgBox(0, "DateTime for User ID " & $sUserId, $sDateTime)
                    $bFound = True
                    ExitLoop
                EndIf
            Next
        EndIf
    Next

    If Not $bFound Then
        MsgBox(48, "User ID Not Found", "The provided User ID was not found in the table.")
    EndIf

 

Edited by jmp
Added New Code
Link to comment
Share on other sites

It should...
But as _IE* funcs are efficient and reliable but slow, when it is possible I personally often choose the string/regex way

$txt = "<tr class=""web-row-style"">" & @crlf & _ 
    "            <td>1</td>" & @crlf & _ 
    "            <td>24/12/2023 09:33:21</td>" & @crlf & _ 
    "            <td>55801</td>    " & @crlf & _ 
    "        </tr>" & @crlf & _ 
    @crlf & _ 
    @crlf & _ 
    "<tr class=""web-alternating-row"">" & @crlf & _ 
    "            <td>2</td>" & @crlf & _ 
    "            <td>24/12/2023 08:51:30</td>" & @crlf & _ 
    "            <td>48887</td>" & @crlf & _ 
    "        </tr>" & @crlf & _ 
    @crlf & _ 
    "<tr class=""web-row-style"">" & @crlf & _ 
    "            <td>3</td>" & @crlf & _ 
    "            <td>23/12/2023 10:51:32</td>" & @crlf & _ 
    "            <td>289261</td>    " & @crlf & _ 
    "        </tr>"
; Msgbox(0,"", $txt)


$id = "48887"
$res = StringRegExpReplace($txt, '(?s).*<td>(.*?)</td>\s*<td>' & $id & '</td>.*', "$1")
Msgbox(0,"", @extended = 0 ? "id not found" : $res)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...