Parse html with jsoup and remove the tag block

后端 未结 4 2006
傲寒
傲寒 2021-01-05 06:00

I want to remove everything between a tag. An example input may be

Input:


  start
  
delete from below
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 06:23

    I asked this problem yesterday and thanks to ollo's answer. It was solved. There is en extension of the above problem. I did not know if I have to start a new post or chain this one. So, in this confusion I am chaining it here.. Admins pls, pardon me if I had to make a separate post for this.

    In the above problem, I have to remove a tag block with matching component.

    The real scenario is: It should remove the tag block with matching component + remove
    surrounding it.

    Referring to the above example.

    
      start
      
    delete from below

    first div having this class
    waste
    second div having this class
    waste

    delete till above
    this will also remain
    end

    should also give the same output:

    
      start
      
    delete from below delete till above
    this will also remain
    end

    Because it has
    above and below the html tag block to remove....

    Just to re-iterate, I am using the solution given by ollo to match and remove the tag block.

    for( Element element : doc.select("div.XYZ") )
    {
        element.remove();
    }
    

    Thanks, Shekhar

提交回复
热议问题