Android 如何忽略Jsoup中的子div标记
我有一段html:Android 如何忽略Jsoup中的子div标记,android,jsoup,Android,Jsoup,我有一段html: <div class="subscribe-page" itemprop="text"><p><strong>Far</strong> behind the word mountains, far from the countries Vokalia and Consonantia.<br> <strong>there:</strong> live the blind texts. Separ
<div class="subscribe-page" itemprop="text"><p><strong>Far</strong> behind the word mountains, far from the countries Vokalia and Consonantia.<br>
<strong>there:</strong> live the blind texts. Separated they live in Bookmarksgrove<br>
<strong>A small:</strong> river named Duden flows by their place and supplies it with the necessary regelialia.</p>
<p>The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen</p>
<div id="form" class="petersemail" lang="en-GB">
<form target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=balmpeters', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true" method="post" action="http://feedburner.google.com/fb/a/mailverify">
<input type="hidden" value="balmpeters" name="uri" />
<input type="hidden" value="en_US" name="loc" />
<span class="fa fa-envelope" style="
top: 29px;
left: 11px;
position: relative;
color: #000;
font-size: 20px;
"></span>
<center> <input class="emailText" type="text" value="Enter your email..." onfocus="if (this.value == "Enter your email...") {this.value = ""}" onblur="if (this.value == "") {this.value = "Enter your email...";}" name="email" /></center>
<div style="
width: 33%;
margin: 3px auto 10px;
"><input type="submit" value="" title="" class="emailButton" /></div>
<p class="stext">Please remember to check your email to confirm the free subscription</p>
</form>
</div>
</div>
问题是它显示的是整个html页面,我有没有办法忽略
及其内容?换句话说,我只想
<div class="subscribe-page" itemprop="text"><p><strong>Far</strong> behind the word mountains, far from the countries Vokalia and Consonantia.<br>
<strong>there:</strong> live the blind texts. Separated they live in Bookmarksgrove<br>
<strong>A small:</strong> river named Duden flows by their place and supplies it with the necessary regelialia.</p>
<p>The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen</p>
远在单词mountains后面,远离Vokalia和Consonantia国家。
那里:直播盲文。他们分别住在Bookmarksgrove
一条名为杜登的小河从他们的住处流过,并为其提供必要的regelialia
大Oxmox建议她不要这样做,因为有成千上万个坏逗号,疯狂的问号和迂回的Semikoli,但小盲文没有听
忽略
元素的一种方法是将其从文档中删除:
document
.select("div#form")
.remove();
之后,你可以使用你的
String page_content = document.select("div.subscribe-page").first().html();
要获取div
(不包含div
本身)的内容。如果要包含div
,只需使用.toString()
而不是.html()
“忽略”
元素的一种方法是将其从文档中删除:
document
.select("div#form")
.remove();
之后,你可以使用你的
String page_content = document.select("div.subscribe-page").first().html();
获取div
的内容(不带div
本身)。如果您想包含div
,只需使用.toString()
而不是.html()
,初始CSS查询(div.subscribe-page
)可以像这样增强:
div.subscribe-page > *:not(div#form)
描述
初始CSS查询(div.subscribe-page
)可以这样增强:
div.subscribe-page > *:not(div#form)
描述
工作得像个魔咒!感谢您的帮助。Jsoup还可以将自己从div中移除。请参阅咒语!感谢您的帮助。Jsoup还可以删除div。查看CSS查询需要一些调整:查看CSS查询需要一些调整:查看Nice!我选择了删除版本b/c,但不清楚OP是否希望包含
div
或notNice!我选择了删除版本b/c,但不清楚OP是否希望包含div