<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 從元素抽取屬性,文本和HTML <div><h2>問題</h2> <p>在解析獲得一個Document實例對象,并查找到一些元素之后,你希望取得在這些元素中的數據。</p> <h2>方法</h2> <ul> <li>要取得一個屬性的值,可以使用<code><a title="Get an attribute's value by its key." href="http://jsoup.org/apidocs/org/jsoup/nodes/Node.html#attr%28java.lang.String%29">Node.attr(String key)</a></code> 方法 </li> <li>對于一個元素中的文本,可以使用<code><a title="Gets the combined text of this element and all its children." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#text%28%29">Element.text()</a></code>方法</li> <li>對于要取得元素或屬性中的HTML內容,可以使用<code><a title="Retrieves the element's inner HTML." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#html%28%29">Element.html()</a></code>, 或 <code><a title="Get the outer HTML of this node." href="http://jsoup.org/apidocs/org/jsoup/nodes/Node.html#outerHtml%28%29">Node.outerHtml()</a></code>方法</li> </ul> <p>示例:</p> <pre><code>String html = "&lt;p&gt;An &lt;a href='http://example.com/'&gt;&lt;b&gt;example&lt;/b&gt;&lt;/a&gt; link.&lt;/p&gt;"; Document doc = Jsoup.parse(html);//解析HTML字符串返回一個Document實現 Element link = doc.select("a").first();//查找第一個a元素 String text = doc.body().text(); // "An example link"//取得字符串中的文本 String linkHref = link.attr("href"); // "http://example.com/"//取得鏈接地址 String linkText = link.text(); // "example""//取得鏈接地址中的文本 String linkOuterH = link.outerHtml(); // "&lt;a href="http://example.com"&gt;&lt;b&gt;example&lt;/b&gt;&lt;/a&gt;" String linkInnerH = link.html(); // "&lt;b&gt;example&lt;/b&gt;"//取得鏈接內的html內容 </code></pre> <h2>說明</h2> <p>上述方法是元素數據訪問的核心辦法。此外還其它一些方法可以使用:</p> <ul> <li><code><a title="Get the id attribute of this element." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#id%28%29">Element.id()</a></code></li> <li><code><a title="Get the name of the tag for this element." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#tagName%28%29">Element.tagName()</a></code></li> <li><code><a title="Gets the literal value of this element's &quot;class&quot; attribute, which may include multiple class names, space separated." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#className%28%29">Element.className()</a></code> and <code><a title="Tests if this element has a class." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#hasClass%28java.lang.String%29">Element.hasClass(String className)</a></code></li></ul> <p>這些訪問器方法都有相應的setter方法來更改數據.</p> <h2>參見</h2> <ul> <li><code><a title="A HTML element consists of a tag name, attributes, and child nodes (including text nodes and other elements)." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html">Element</a></code>和<code><a title="A list of Elements, with methods that act on every element in the list." href="http://jsoup.org/apidocs/org/jsoup/select/Elements.html">Elements</a></code>集合類的參考文檔</li> <li><a href="http://www.open-open.com/jsoup/working-with-urls.htm">URLs處理</a></li> <li><a href="http://www.open-open.com/jsoup/selector-syntax.htm">使用CSS選擇器語法來查找元素</a></li></ul></div>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看