JSoup无法在深度2之后解析子元素

时间:2018-09-16 17:02:34

标签: java html jsoup

我正在尝试解析某些文档站点的侧边栏目录。我只能在深度2之前获得子元素。

public String ExtractHTMLByIDandDomain(String URL,String ID) throws IOException
{        
   Document doc = Jsoup.connect(URL).get();
   Element element=doc.getElementById(ID);
   System.out.println(element);  
   //return element; 
}

网站摘录来源:https://docs.microsoft.com/en-us/ef/ef6/

输出:

<nav class="sidebar" id="sidebar" data-bi-name="left toc" role="navigation" aria-label="Main Navigation"> 
 <button class="sidebar-header" type="button" aria-label="Close" data-bi-name="contents-collapse"> <span>Contents</span> <span class="docon docon-navigate-close" aria-hidden="true"></span> </button> 
 <div id="sidebarContent"> 
  <div class="filterHolder"> 
  </div> 
  <nav class="toc"></nav> 
  <div class="pdfDownloadHolder"></div> 
 </div> 
</nav>

预期输出:

<nav class="sidebar" id="sidebar" data-bi-name="left toc" role="navigation" aria-label="Main Navigation"> 
 <button class="sidebar-header" type="button" aria-label="Close" data-bi-name="contents-collapse"> <span>Contents</span> <span class="docon docon-navigate-close" aria-hidden="true"></span> </button> 
 <div id="sidebarContent"> 
  <div class="filterHolder"> 
  </div>
   ...
<nav class="toc" role="application" aria-label="Table of Contents" id="filterResults">
   <ul role="tree" onclick="msDocs.functions.stopSomePropagation(event, &quot;top&quot;)" class="noSibs hideFocus">
      <li role="group" aria-expanded="true" aria-label="entity framework " onclick="event.stopPropagation();msDocs.functions.toggleAriaExpanded(this)">
         <a onclick="msDocs.functions.stopSomePropagation(event, &quot;left&quot;)" tabindex="0" href="/en-us/ef/" data-text="entity framework " class="x-hidden-focus">Entity Framework</a>
         <ul role="tree" onclick="msDocs.functions.stopSomePropagation(event, &quot;top&quot;)">
           ...
      </li>
   </ul>
</nav>

0 个答案:

没有答案
相关问题