Click here to Skip to main content
15,887,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got a html file like this:
HTML
<!document>
<!--alo 123-->
<html>
<head>
<title>TEST</title>
</head>
<body>
<!--alo 123-->
<span>hello and cut the site</span>

<div>
<header>
<div>
<!--alo 123-->
<span>header here!</span>
</div>
</header>
</div>

<p> This is 123</p>
<content >
<!--alo 123-->
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</content>
<p> This is 345</p>

<div>
<!--alo 123-->
<footer><!--alo 123-->
<div>footer here</div></footer>
</div>
<br/>
<h2>hahaha</h2>
</body>
</html>



With Jsoup, i got
HTML
<div>
tag, which before my <content> tag; and
HTML
<div>
tags, which are before/after
HTML
<content>
tag as arguments in my function:

C#
private  void extractPage(Element previousTag,Element nextTag)throws IOException    
{ 
        Document doc = getDocHTML("product.html");      
        String str=previousTag.tagName()+"~*";
        Elements rs= doc.select(str);   
        String str2=nextTag.tagName()+"~*";       
        Elements rs2=rs.select(str2).remove();        
        this.messager.show(rs.outerHtml());
    }


I want to extract everything between my 2 previousTag and nextTag.
But with my function, i can't do it now.
I want to get result as this :

HTML
<p> This is 123</p>
<content >
<!--alo 123-->
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</content>
<p> This is 345</p>


Please help me.
Posted
Updated 7-May-16 18:36pm
v2
Comments
Mohibur Rashid 8-May-16 3:21am    
Have you tried Google? Try this link
TokiHana 8-May-16 5:06am    
With that link, i ended up to ask this forum.
Mohibur Rashid 8-May-16 5:21am    
I can still go to the correct address. I will ask you again, did you try Google? https://jsoup.org/cookbook/extracting-data/selector-syntax
TokiHana 8-May-16 20:11pm    
Form there, i did come up extractPage. But it doesn't work correctly. That's y i am asking.
Actually i did it with loop for. But i want to know how to how to remove loop for.
Anyway, thank you a lot for helping me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900