简体   繁体   English

Jsoup无法选择p元素作为父元素

[英]Jsoup cannot select p element as a parent element

Using Jsoup I am trying to find wrong html constructions like: 使用Jsoup,我试图找到错误的html结构,例如:

<body><p><h1>some text</h1></p></body>

I first select the heading tag and then use headingElement.parent() to get the parent of this h1 tag. 我首先选择标题标签,然后使用headingElement.parent()获取此h1标签的父级。 but instead of p as its parent I get body . 但不是p作为其父我得到body Does anyone know why? 有人知道为什么吗?

JSoup解析HTML时,就像任何良好的HTML解析器一样,已经应用了规则,即<h1>标签会自动关闭所有打开的<p>元素,因此<p><h1>已经是同级子级DOM中<body>元素的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM