Jump to content

Recommended Posts

Posted (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 by Nareshm
add id instead of name
Posted (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 by Subz
Updated thanks @Nine
Posted
1 hour ago, Nareshm said:

@Juvigy

i want to delete id 

Capture12.JPG

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

 

Posted
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.

Posted
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

Posted
14 minutes ago, Nareshm said:

@Dionysis

Error in line 4

 

Capture33.JPG

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.

Posted

@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...

Posted (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 by Nareshm
Posted
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

Posted
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.

Posted
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

Capturehh.JPG

Posted (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 by Subz
Updated thanks @Nine
Posted
5 minutes ago, Nareshm said:

@Dionysis Thank You, But error during restoring id

Capturehh.JPG

If you have a "=" operator and it says you don't, I bet you have a rogue double question-mark somewhere...

Posted
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

 

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
  • Recently Browsing   0 members

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