使用 jsoup 获取文本
get text with jsoup
我有这个HTML
<ul id="items"><li>
<p><strong><span class="style4"><strong>Lifts open today include Agassiz to the top, Sunset, Hart Prairie, Little and Big Spruce from <br />
9 a.m. - 4 p.m.</strong></span></strong></p>
</li>
</ul>
<h3> </h3>
<h3>Trails Open<br />
</h3>
<ul id="items">
<li class="style4">
<p><strong><span class="style4">100% of trails open with 30 groomed runs. </span></strong></p>
</li>
</ul>
我要文字"Lifts open today....."
这是我的代码。什么都没有显示。 logcat
没有错误
文档 doc = Jsoup.connect(url).get();
Elements div = doc.select("div.right");
for (Element liftope : div){
Elements p =liftope.select("#items > li > p");
liftoper = p.text();
}
怎么了???
如果您只想要那个文本 "Lifts open today include: Agassiz to the top, Sunset, Hart Prairie, Aspen and Little Spruce Conveyor!" 这个(我尝试)有效:
Element div = doc.getElementById("contentinterior");
Elements uls = div.getElementsByTag("ul");
Element ul = uls.get(2);
String result = ul.text();
我有这个HTML
<ul id="items"><li>
<p><strong><span class="style4"><strong>Lifts open today include Agassiz to the top, Sunset, Hart Prairie, Little and Big Spruce from <br />
9 a.m. - 4 p.m.</strong></span></strong></p>
</li>
</ul>
<h3> </h3>
<h3>Trails Open<br />
</h3>
<ul id="items">
<li class="style4">
<p><strong><span class="style4">100% of trails open with 30 groomed runs. </span></strong></p>
</li>
</ul>
我要文字"Lifts open today....."
这是我的代码。什么都没有显示。 logcat
没有错误文档 doc = Jsoup.connect(url).get();
Elements div = doc.select("div.right");
for (Element liftope : div){
Elements p =liftope.select("#items > li > p");
liftoper = p.text();
}
怎么了???
如果您只想要那个文本 "Lifts open today include: Agassiz to the top, Sunset, Hart Prairie, Aspen and Little Spruce Conveyor!" 这个(我尝试)有效:
Element div = doc.getElementById("contentinterior");
Elements uls = div.getElementsByTag("ul");
Element ul = uls.get(2);
String result = ul.text();