【问题标题】:get text with jsoup使用 jsoup 获取文本
【发布时间】:2015-04-30 22:33:43
【问题描述】:

我有这个 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>

我想要文本“电梯今天开放.....”


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

怎么了???

【问题讨论】:

    标签: html jsoup


    【解决方案1】:

    如果您只想要“今天开放的电梯包括:Agassiz to the top、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();
    

    【讨论】:

    • @AgustinScalisi 你能发布所有的 html 吗?
    • 基于这个页面arizonasnowbowl.com/resort/snow_report.php我想在这个CSS路径上显示文字#items > li > p > strong > span > strong
    • @AgustinScalisi 检查我的更新答案,我尝试工作
    • @AgustinScalisi 如果您满意并且答案有用,您可以接受!再见!
    • @AgustinScalisi 我认为您可以接受答案,我在这里阅读:meta.stackexchange.com/questions/5234/…
    猜你喜欢
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    相关资源
    最近更新 更多