jmp Posted December 25, 2023 Share Posted December 25, 2023 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 More sharing options...
mikell Posted December 25, 2023 Share Posted December 25, 2023 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 Link to comment Share on other sites More sharing options...
jmp Posted December 25, 2023 Author Share Posted December 25, 2023 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 More sharing options...
mikell Posted December 25, 2023 Share Posted December 25, 2023 Exactly what I meant. Using _IETableWriteToArray you get a 2D array which contains DateTime and the corresponding User ID on the same rows Link to comment Share on other sites More sharing options...
jmp Posted December 25, 2023 Author Share Posted December 25, 2023 (edited) 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 December 25, 2023 by jmp Link to comment Share on other sites More sharing options...
Nine Posted December 25, 2023 Share Posted December 25, 2023 Use the suggestion of Mikell, and _ArraySearch to get the index of the row you want based on UserId. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jmp Posted December 25, 2023 Author Share Posted December 25, 2023 @Nine I can't understand _ArraySearch 😴 Link to comment Share on other sites More sharing options...
Nine Posted December 25, 2023 Share Posted December 25, 2023 Maybe programming is not for you then. Or shape up and work on it... Danp2 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jmp Posted December 25, 2023 Author Share Posted December 25, 2023 @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 More sharing options...
mikell Posted December 25, 2023 Share Posted December 25, 2023 Maybe the array way ? Link to comment Share on other sites More sharing options...
jmp Posted December 25, 2023 Author Share Posted December 25, 2023 @mikell Can you please give me an example? Link to comment Share on other sites More sharing options...
jmp Posted December 26, 2023 Author Share Posted December 26, 2023 (edited) @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 December 26, 2023 by jmp Added New Code Link to comment Share on other sites More sharing options...
mikell Posted December 26, 2023 Share Posted December 26, 2023 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now