0

这个JSoup在这里加倍body标签的内容有什么原因吗?

public static void main(String[] args) {
    Jsoup.parse(myHtmlString).body().getAllElements()
}

它确实发生在这个 html 代码中:

<html>
 <head> 
  <style> p{margin-bottom:0px;margin-top:0px;} body{font-family:Arial;font-size:10pt;} </style> 
 </head> 
 <body> 
  <div class="wordsection1"> 
   <p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p> 
   <p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p> 
   <div> 
    <div style="padding-top:3.0pt;padding-left:0cm;padding-right:0cm;padding-bottom:0cm;border-left-style:none;border-top-width:1.0pt;border-bottom-style:none;border-right-style:none;border-top-color:#B5C4DF;border-top-style:solid;"> 
     <p class="msonormal"> <b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b><span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] <br><b>Gesendet:</b> Dienstag, 6. August 2013 08:59<br><b>An:</b> Helmut Grashoff (dsfaasas@gmbh.de)<br><b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span></p> 
    </div> 
   </div> 
   <p class="msonormal">&nbsp;</p> 
   <p class="msonormal">Erst schauen wir mal, ob die Mail &uuml;berhaupt ankommt.</p> 
   <p class="msonormal">&nbsp;</p> 
   <p class="msonormal">Und <i> <u>gleichzeitig</u></i> <span style="font-size:18.0pt;">spiele</span> ich noch ein <span style="color:#31859C;">wenig </span> <span style="font-family:Algerian;">mit dieser Zeile</span></p> 
   <p class="msonormal">&nbsp;</p> 
   <p class="msonormal"> <span mso-fareast-language="DE">Mit freundlichen Gruessen</span></p> 
   <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
   <p class="msonormal"> <span mso-fareast-language="DE" style="color:#31849B;">Uasdsaa Aasdsaa</span></p> 
   <p class="msonormal"> <span mso-fareast-language="DE" style="font-size:9.0pt;">Iasdsaa-Sasdsaa</span></p> 
   <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
   <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p> 
   <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p> 
   <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">56218 M&uuml;lheim-K&auml;rlich</span></p> 
   <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
   <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
   <p class="msonormal">&nbsp;</p> 
  </div> 
 </body>
</html>

以上解析方法的结果,并不是说这里只是body部分的内容:

<body> 
 <div class="wordsection1"> 
  <p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p> 
  <p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p> 
  <div> 
   <div style="padding-top:3.0pt;padding-left:0cm;padding-right:0cm;padding-bottom:0cm;border-left-style:none;border-top-width:1.0pt;border-bottom-style:none;border-right-style:none;border-top-color:#B5C4DF;border-top-style:solid;"> 
    <p class="msonormal"> <b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b><span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] Br2nL<b>Gesendet:</b> Dienstag, 6. August 2013 08:59Br2nL<b>An:</b> Helmut Grashoff (asdafsdf@gmbh.de)Br2nL<b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span></p> 
   </div> 
  </div> 
  <p class="msonormal">&nbsp;</p> 
  <p class="msonormal">Erst schauen wir mal, ob die Mail &uuml;berhaupt ankommt.</p> 
  <p class="msonormal">&nbsp;</p> 
  <p class="msonormal">Und <i> <u>gleichzeitig</u></i> <span style="font-size:18.0pt;">spiele</span> ich noch ein <span style="color:#31859C;">wenig </span> <span style="font-family:Algerian;">mit dieser Zeile</span></p> 
  <p class="msonormal">&nbsp;</p> 
  <p class="msonormal"> <span mso-fareast-language="DE">Mit freundlichen Gruessen</span></p> 
  <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
  <p class="msonormal"> <span mso-fareast-language="DE" style="color:#31849B;">Uasdsaa Aasdsaa</span></p> 
  <p class="msonormal"> <span mso-fareast-language="DE" style="font-size:9.0pt;">Iasdsaa-Sasdsaa</span></p> 
  <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
  <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p> 
  <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p> 
  <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">56218 M&uuml;lheim-K&auml;rlich</span></p> 
  <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
  <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
  <p class="msonormal">&nbsp;</p> 
 </div>  
</body>
<div class="wordsection1"> 
 <p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p> 
 <p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p> 
 <div> 
  <div style="padding-top:3.0pt;padding-left:0cm;padding-right:0cm;padding-bottom:0cm;border-left-style:none;border-top-width:1.0pt;border-bottom-style:none;border-right-style:none;border-top-color:#B5C4DF;border-top-style:solid;"> 
   <p class="msonormal"> <b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b><span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] Br2nL<b>Gesendet:</b> Dienstag, 6. August 2013 08:59Br2nL<b>An:</b> Helmut Grashoff (asfasd@gmbh.de)Br2nL<b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span></p> 
  </div> 
 </div> 
 <p class="msonormal">&nbsp;</p> 
 <p class="msonormal">Erst schauen wir mal, ob die Mail &uuml;berhaupt ankommt.</p> 
 <p class="msonormal">&nbsp;</p> 
 <p class="msonormal">Und <i> <u>gleichzeitig</u></i> <span style="font-size:18.0pt;">spiele</span> ich noch ein <span style="color:#31859C;">wenig </span> <span style="font-family:Algerian;">mit dieser Zeile</span></p> 
 <p class="msonormal">&nbsp;</p> 
 <p class="msonormal"> <span mso-fareast-language="DE">Mit freundlichen Gruessen</span></p> 
 <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
 <p class="msonormal"> <span mso-fareast-language="DE" style="color:#31849B;">Uasdsaa Aasdsaa</span></p> 
 <p class="msonormal"> <span mso-fareast-language="DE" style="font-size:9.0pt;">Iasdsaa-Sasdsaa</span></p> 
 <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
 <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p> 
 <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p> 
 <p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">56218 M&uuml;lheim-K&auml;rlich</span></p> 
 <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
 <p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p> 
 <p class="msonormal">&nbsp;</p> 
</div>
<p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p>
<span style="color:#1F497D;">&nbsp;</span>
<p class="msonormal"> <span style="color:#1F497D;">&nbsp;</span></p>
<span style="color:#1F497D;">&nbsp;</span>
<div> 
 <div style="padding-top:3.0pt;padding-left:0cm;padding-right:0cm;padding-bottom:0cm;border-left-style:none;border-top-width:1.0pt;border-bottom-style:none;border-right-style:none;border-top-color:#B5C4DF;border-top-style:solid;"> 
  <p class="msonormal"> <b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b><span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] Br2nL<b>Gesendet:</b> Dienstag, 6. August 2013 08:59Br2nL<b>An:</b> Helmut Grashoff (asdffasd@gmbh.de)Br2nL<b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span></p> 
 </div> 
</div>
<div style="padding-top:3.0pt;padding-left:0cm;padding-right:0cm;padding-bottom:0cm;border-left-style:none;border-top-width:1.0pt;border-bottom-style:none;border-right-style:none;border-top-color:#B5C4DF;border-top-style:solid;"> 
 <p class="msonormal"> <b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b><span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] Br2nL<b>Gesendet:</b> Dienstag, 6. August 2013 08:59Br2nL<b>An:</b> Helmut Grashoff (asdfsad@gmbh.de)Br2nL<b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span></p> 
</div>
<p class="msonormal"> <b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b><span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] Br2nL<b>Gesendet:</b> Dienstag, 6. August 2013 08:59Br2nL<b>An:</b> Helmut Grashoff (asdfsdfa@gmbh.de)Br2nL<b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span></p>
<b> <span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span></b>
<span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;">Von:</span>
<span tahoma","sans-serif";mso-fareast-language:de"="" style="font-size:10.0pt;"> Uasdsaa Aasdsaa [mailto:bullet1@left.de] Br2nL<b>Gesendet:</b> Dienstag, 6. August 2013 08:59Br2nL<b>An:</b> Helmut Grashoff (asdfsdf@gmbh.de)Br2nL<b>Betreff:</b> erster Test f&uuml;r die 2.2.1 (mit HTML)</span>
<b>Gesendet:</b>
<b>An:</b>
<b>Betreff:</b>
<p class="msonormal">&nbsp;</p>
<p class="msonormal">Erst schauen wir mal, ob die Mail &uuml;berhaupt ankommt.</p>
<p class="msonormal">&nbsp;</p>
<p class="msonormal">Und <i> <u>gleichzeitig</u></i> <span style="font-size:18.0pt;">spiele</span> ich noch ein <span style="color:#31859C;">wenig </span> <span style="font-family:Algerian;">mit dieser Zeile</span></p>
<i> <u>gleichzeitig</u></i>
<u>gleichzeitig</u>
<span style="font-size:18.0pt;">spiele</span>
<span style="color:#31859C;">wenig </span>
<span style="font-family:Algerian;">mit dieser Zeile</span>
<p class="msonormal">&nbsp;</p>
<p class="msonormal"> <span mso-fareast-language="DE">Mit freundlichen Gruessen</span></p>
<span mso-fareast-language="DE">Mit freundlichen Gruessen</span>
<p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p>
<span mso-fareast-language="DE">&nbsp;</span>
<p class="msonormal"> <span mso-fareast-language="DE" style="color:#31849B;">Uasdsaa Aasdsaa</span></p>
<span mso-fareast-language="DE" style="color:#31849B;">Uasdsaa Aasdsaa</span>
<p class="msonormal"> <span mso-fareast-language="DE" style="font-size:9.0pt;">Iasdsaa-Sasdsaa</span></p>
<span mso-fareast-language="DE" style="font-size:9.0pt;">Iasdsaa-Sasdsaa</span>
<p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p>
<span mso-fareast-language="DE">&nbsp;</span>
<p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p>
<span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span>
<p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span></p>
<span verdana","sans-serif";mso-fareast-language:de"="">asdsaa</span>
<p class="msonormal"> <span verdana","sans-serif";mso-fareast-language:de"="">56218 M&uuml;lheim-K&auml;rlich</span></p>
<span verdana","sans-serif";mso-fareast-language:de"="">56218 M&uuml;lheim-K&auml;rlich</span>
<p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p>
<span mso-fareast-language="DE">&nbsp;</span>
<p class="msonormal"> <span mso-fareast-language="DE">&nbsp;</span></p>
<span mso-fareast-language="DE">&nbsp;</span>
<p class="msonormal">&nbsp;</p>

我正在使用 Java 6 和 Jsoup 1.7.2。

4

1 回答 1

0

它明显而完美。

事实上,它不会翻倍,而是重复Elements 与参考深度一样多的次数Node

每一个Nodebody都被认为是Element包括在内body,直到它到达叶子Node

如果考虑文本<b>Betreff:</b>It 重复 7 次,它在根 ( <body>) 之下 7 级,也是树中深度更大的子节点。

body > div >div > div > p > span >b

于 2013-08-27T18:23:48.123 回答