0

我正在构建一个 Android 应用程序,并使用库 jsoup,我正在解析 html,但不知道如何从我的 html 中获取项目

的HTML:

<div id="polls-687" class="wp-polls">
            <form id="polls_form_687" class="wp-polls-form" action="/myurl" method="post">
                <p style="display: none;">
                    <input type="hidden" id="poll_687_nonce" name="wp-polls-nonce" value="6490c2e4b0" />
                </p>
                <p style="display: none;">
                    <input type="hidden" name="poll_id" value="687" />
                </p>

                <h4>What do you want to hear?</h4>
                <div id="polls-687-ans" class="wp-polls-ans">
                    <ul class="wp-polls-ul" style="padding-left:0px;">
                        <li>
                            <input type="radio" id="poll-answer-2605" name="poll_687" value="2605" />
                            <label for="poll-answer-2605">Cappella - U & Me</label>
                        </li>

                        <li>
                            <input type="radio" id="poll-answer-2607" name="poll_687" value="2607" />
                            <label for="poll-answer-2607">Deepest Blue - Deepest Blue</label>
                        </li>

                        <li>
                            <input type="radio" id="poll-answer-2609" name="poll_687" value="2609" />
                            <label for="poll-answer-2609">Britney Spears - (Hit Me Baby) One More Time</label>
                        </li>

                        <li>
                            <input type="radio" id="poll-answer-2611" name="poll_687" value="2611" />
                            <label for="poll-answer-2611">Drukwerk - Marianneke</label>
                        </li>
                    </ul>

                    <p style="text-align: left;">
                        <input type="button" name="vote" value="   Stem op deze plaat   " class="Buttons" onclick="poll_vote(687);" />
                    </p>

                    <p style="text-align: left;">
                    </p>
                </div>
            </form>
        </div>

我需要获取 li 标签之间的标签。还有来自输入标签的值。我已使用此链接http://jsoup.org/cookbook/extracting-data/attributes-text-html但我不知道您如何获得我需要的特定项目。有人有使用 Jsoup 的经验并给我一些建议或例子吗?

4

1 回答 1

1

尝试这个

     Elements inputElements = document.select("ul li input");
         for (Iterator<Element> iterator = inputElements.iterator();     iterator.hasNext();) 
         { 
            Element inputElement = iterator.next();
            Element labelElement = inputElement.nextElementSibling();
            System.out.println(inputElement.attr("value"));
            System.out.println(labelElement.ownText());
         }
于 2013-07-15T21:37:53.870 回答