naru Posted March 6, 2019 Posted March 6, 2019 (edited) My html page have multiple id with same name, and I want to skip first one and delete second Line. I tried with this code but it was removing first id/line #include <IE.au3> $oIE = _IEAttach ("Final Print") $Drceiptdetails = _IEGetObjById($oIE, "receiptdetails") $Dreceiptdetails.RemoveNode(True) $Dprintdetails = _IEGetObjById($oIE, "printdetails") $Dprintdetails.RemoveNode(True) Exit Edited March 6, 2019 by Nareshm add id instead of name
Juvigy Posted March 6, 2019 Posted March 6, 2019 Thats not the name, but the ID. Show us the html code in order to suggest what to do.
naru Posted March 6, 2019 Author Posted March 6, 2019 (edited) @Juvigy i want to delete id Edited March 6, 2019 by Nareshm
Subz Posted March 6, 2019 Posted March 6, 2019 (edited) Maybe something like: _DeleteNode($oIE, "div", "id", "printdetails", 2) Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1) Local $iTagInstance = 1 Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType) If IsObj($oTagNameColl) Then For $i = 0 To $oTagNameColl.length - 1 If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then If $iTagInstance = $_iDelInstance Then $oTagNameColl($i).RemoveNode(True) ExitLoop EndIf $iTagInstance += 1 EndIf Next EndIf EndFunc Edited March 7, 2019 by Subz Updated thanks @Nine
Dionysis Posted March 6, 2019 Posted March 6, 2019 1 hour ago, Nareshm said: @Juvigy i want to delete id If the html page is yours (so you have the permissions to edit the code), you should alter the IDs to stop the infringement. For a quick fix you can just change the first id temporarily to access the second one, sth like this: #include <IE.au3> $oIE = _IEAttach ("Final Print") $Drceiptdetails1 = _IEGetObjById($oIE, "receiptdetails") ; get first object $Drceiptdetails1.id = "receiptdetails1" ; change it's id $Drceiptdetails = _IEGetObjById($oIE, "receiptdetails") ; get second object $Dreceiptdetails.RemoveNode(True) ; remove it $Drceiptdetails1.id = "receiptdetails" ; restore the first object's id Exit
naru Posted March 6, 2019 Author Posted March 6, 2019 1 minute ago, Dionysis said: If the html page is yours (so you have the permissions to edit the code), you should alter the IDs to stop the infringement. For a quick fix you can just change the first id temporarily to access the second one, sth like this: #include <IE.au3> $oIE = _IEAttach ("Final Print") $Drceiptdetails1 = _IEGetObjById($oIE, "receiptdetails") ; get first object $Drceiptdetails1.id = "receiptdetails1" ; change it's id $Drceiptdetails = _IEGetObjById($oIE, "receiptdetails") ; get second object $Dreceiptdetails.RemoveNode(True) ; remove it $Drceiptdetails1.id = "receiptdetails" ; restore the first object's id Exit It's not my own html page.
Dionysis Posted March 6, 2019 Posted March 6, 2019 Just now, Nareshm said: It's not my own html page. So just use the code I posted
naru Posted March 6, 2019 Author Posted March 6, 2019 11 minutes ago, Dionysis said: So just use the code I posted @Dionysis Error in line 4
naru Posted March 6, 2019 Author Posted March 6, 2019 1 hour ago, Subz said: Maybe something like: _DeleteNode($oIE, "div", "id", "printdetails") Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 2) Local $iTagInstance = 1 Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType) If IsObj($oTagNameColl) Then For $i = 0 To $oTagNameColl.length - 1 If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then If $iTagInstance = $_iDelInstance Then $oTagNameColl($i).RemoveNode(True) EndIf EndIf $iTagInstance += 1 Next EndIf EndFunc @Subz it was not deleting anything
Dionysis Posted March 6, 2019 Posted March 6, 2019 14 minutes ago, Nareshm said: @Dionysis Error in line 4 Yeah... I just changed your code, so maybe you meant $Dreceiptdetails instead of $Drceiptdetails. I tried my code by changing the _IEGetObjById example to: #include <IE.au3> Local $oIE = _IE_Example("basic") $temp = _IEGetObjById($oIE, "line1") $temp.id = "line2" ;now we have two "line2" IDs MsgBox(0,"body.innerHTML Before",_IETagNameGetCollection($oIE,"body",0).innerHTML) Local $oDiv = _IEGetObjById($oIE, "line2") ; select the first object $oDiv.id = "sthelse" ; change the first ID to something else $oDiv2 = _IEGetObjById($oIE, "line2") ;select the second object $oDiv2.RemoveNode(True) $oDiv.id = "line2" ;restore the first object's ID MsgBox(0,"body.innerHTML After",_IETagNameGetCollection($oIE,"body",0).innerHTML) Exit It works as it is, so you can run it and see what's different in your code.
Nine Posted March 6, 2019 Posted March 6, 2019 @Subz & @Dionysis There was a small bug in subz code : Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1) Local $iTagInstance = 1 Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType) If IsObj($oTagNameColl) Then For $i = 0 To $oTagNameColl.length - 1 If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then If $iTagInstance = $_iDelInstance Then $oTagNameColl($i).RemoveNode(True) ExitLoop EndIf $iTagInstance += 1 EndIf Next EndIf EndFunc Increment of $iTagInstance was misplaced... “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
naru Posted March 7, 2019 Author Posted March 7, 2019 (edited) 20 hours ago, Dionysis said: Yeah... I just changed your code, so maybe you meant $Dreceiptdetails instead of $Drceiptdetails. I tried my code by changing the _IEGetObjById example to: #include <IE.au3> Local $oIE = _IE_Example("basic") $temp = _IEGetObjById($oIE, "line1") $temp.id = "line2" ;now we have two "line2" IDs MsgBox(0,"body.innerHTML Before",_IETagNameGetCollection($oIE,"body",0).innerHTML) Local $oDiv = _IEGetObjById($oIE, "line2") ; select the first object $oDiv.id = "sthelse" ; change the first ID to something else $oDiv2 = _IEGetObjById($oIE, "line2") ;select the second object $oDiv2.RemoveNode(True) $oDiv.id = "line2" ;restore the first object's ID MsgBox(0,"body.innerHTML After",_IETagNameGetCollection($oIE,"body",0).innerHTML) Exit It works as it is, so you can run it and see what's different in your code. Example running Good but in my codeI get same error. Edited March 7, 2019 by Nareshm
Dionysis Posted March 7, 2019 Posted March 7, 2019 1 minute ago, Nareshm said: Example running Good but in my codeI get same error. I can't see how we can help with this... I suppose you corrected the Drceiptdetails or Dreceiptdetails
naru Posted March 7, 2019 Author Posted March 7, 2019 16 hours ago, Nine said: @Subz & @Dionysis There was a small bug in subz code : Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1) Local $iTagInstance = 1 Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType) If IsObj($oTagNameColl) Then For $i = 0 To $oTagNameColl.length - 1 If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then If $iTagInstance = $_iDelInstance Then $oTagNameColl($i).RemoveNode(True) ExitLoop EndIf $iTagInstance += 1 EndIf Next EndIf EndFunc Increment of $iTagInstance was misplaced... @Nine Thank You But, it was Deleting first id not second.
naru Posted March 7, 2019 Author Posted March 7, 2019 10 minutes ago, Dionysis said: I can't see how we can help with this... I suppose you corrected the Drceiptdetails or Dreceiptdetails @Dionysis Thank You, But error during restoring id
Subz Posted March 7, 2019 Posted March 7, 2019 (edited) You would need to set the last parameter: _DeleteNode($oIE, "div", "id", "printdetails", 2) Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1) Local $iTagInstance = 1 Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType) If IsObj($oTagNameColl) Then For $i = 0 To $oTagNameColl.length - 1 If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then If $iTagInstance = $_iDelInstance Then $oTagNameColl($i).RemoveNode(True) ExitLoop EndIf $iTagInstance += 1 EndIf Next EndIf EndFunc Edited March 7, 2019 by Subz Updated thanks @Nine
Nine Posted March 7, 2019 Posted March 7, 2019 5 minutes ago, Nareshm said: it was Deleting first id not second. Yes normal the parameter $_iDelInstance = 1, call it with 2 then... “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Dionysis Posted March 7, 2019 Posted March 7, 2019 5 minutes ago, Nareshm said: @Dionysis Thank You, But error during restoring id If you have a "=" operator and it says you don't, I bet you have a rogue double question-mark somewhere...
Nine Posted March 7, 2019 Posted March 7, 2019 @Subz change your code, you still have $iTagInstance += 1 misplaced Subz 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
naru Posted March 7, 2019 Author Posted March 7, 2019 3 minutes ago, Nine said: @Subz change your code, you still have $iTagInstance += 1 misplaced Yes @Subz, Its Like This : Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 2) Local $iTagInstance = 1 Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType) If IsObj($oTagNameColl) Then For $i = 0 To $oTagNameColl.length - 1 If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then If $iTagInstance = $_iDelInstance Then $oTagNameColl($i).RemoveNode(True) ExitLoop EndIf $iTagInstance += 1 EndIf Next EndIf EndFunc
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