Search code examples
htmldomxpathelementremovechild

how to remove items from DOM and XPath in my browser?


I hope somebody can help. I'm trying to remove items from ebay listings with the Firefox addon RIP (remove it permanently) which uses XPath and removes selected paths. As a side note: the addon is quite old and so it only works with old versions of Firefox. But I think the addon itself is not really relevant for the solution since I guess it's an XPath problem that needs to be solved.

So for example, if I want to remove every item on this ebay listing:

ebay listing

that contains the keyword "Agfa" I try this (after checking the source code of the webpage):

//li[@class='s-item s-item__pl-on-bottom']/img[contains(@alt,'Agfa')]

I have also tried different approaches but to no avail. The items would not get removed. Note that the ebay listings are updated all the time, so you will need to try with other keywords that are currently in the listing.

does anybody have a clue how to do it?


Solution

  • What I sucessfully done to remove Agfa item in dev tools of your browser:

    $x('//li[@data-viewport][contains(., "AGFA")]')[0].remove()
    

    For multiples items:

    $x('//li[@data-viewport][contains(., "AGFA")]').filter(elt => elt.remove())
    

    If you just need the XPath to feed RIP :

    '//li[@data-viewport][contains(., "AGFA")]'