用jsoup获取文本

时间:2015-02-28 04:49:17

标签: html 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>&nbsp;</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>

我希望文字&#34;电梯今天开放......&#34;


这是我的代码。什么都没有显示。 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();
            }

有什么问题???

1 个答案:

答案 0 :(得分:1)

如果你只想要那个文字“今天开放的电梯包括:Agassiz到顶部,Sunset,Hart Prairie,Aspen和Little Spruce Conveyor!”这(我尝试)工作:

Element div = doc.getElementById("contentinterior");
Elements uls = div.getElementsByTag("ul");
Element ul = uls.get(2);
String result = ul.text();