<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 示例程序 獲取所有鏈接 <div><div><div><p>這個示例程序將展示如何從一個URL獲得一個頁面。然后提取頁面中的所有鏈接、圖片和其它輔助內容。并檢查URLs和文本信息。</p> <p>運行下面程序需要指定一個URLs作為參數</p> <pre><code>package org.jsoup.examples; import org.jsoup.Jsoup; import org.jsoup.helper.Validate; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.io.IOException; /** * Example program to list links from a URL. */ public class ListLinks { public static void main(String[] args) throws IOException { Validate.isTrue(args.length == 1, "usage: supply url to fetch"); String url = args[0]; print("Fetching %s...", url); Document doc = Jsoup.connect(url).get(); Elements links = doc.select("a[href]"); Elements media = doc.select("[src]"); Elements imports = doc.select("link[href]"); print("\nMedia: (%d)", media.size()); for (Element src : media) { if (src.tagName().equals("img")) print(" * %s: &lt;%s&gt; %sx%s (%s)", src.tagName(), src.attr("abs:src"), src.attr("width"), src.attr("height"), trim(src.attr("alt"), 20)); else print(" * %s: &lt;%s&gt;", src.tagName(), src.attr("abs:src")); } print("\nImports: (%d)", imports.size()); for (Element link : imports) { print(" * %s &lt;%s&gt; (%s)", link.tagName(),link.attr("abs:href"), link.attr("rel")); } print("\nLinks: (%d)", links.size()); for (Element link : links) { print(" * a: &lt;%s&gt; (%s)", link.attr("abs:href"), trim(link.text(), 35)); } } private static void print(String msg, Object... args) { System.out.println(String.format(msg, args)); } private static String trim(String s, int width) { if (s.length() &gt; width) return s.substring(0, width-1) + "."; else return s; } } <p><a href="http://github.com/jhy/jsoup/blob/master/src/main/java/org/jsoup/examples/ListLinks.java">org/jsoup/examples/ListLinks.java</a></p></code></pre> <h2>示例輸入結果</h2> <pre><code>Fetching http://news.ycombinator.com/... Media: (38) * img: &lt;http://ycombinator.com/images/y18.gif&gt; 18x18 () * img: &lt;http://ycombinator.com/images/s.gif&gt; 10x1 () * img: &lt;http://ycombinator.com/images/grayarrow.gif&gt; x () * img: &lt;http://ycombinator.com/images/s.gif&gt; 0x10 () * script: &lt;http://www.co2stats.com/propres.php?s=1138&gt; * img: &lt;http://ycombinator.com/images/s.gif&gt; 15x1 () * img: &lt;http://ycombinator.com/images/hnsearch.png&gt; x () * img: &lt;http://ycombinator.com/images/s.gif&gt; 25x1 () * img: &lt;http://mixpanel.com/site_media/images/mixpanel_partner_logo_borderless.gif&gt; x (Analytics by Mixpan.) Imports: (2) * link &lt;http://ycombinator.com/news.css&gt; (stylesheet) * link &lt;http://ycombinator.com/favicon.ico&gt; (shortcut icon) Links: (141) * a: &lt;http://ycombinator.com&gt; () * a: &lt;http://news.ycombinator.com/news&gt; (Hacker News) * a: &lt;http://news.ycombinator.com/newest&gt; (new) * a: &lt;http://news.ycombinator.com/newcomments&gt; (comments) * a: &lt;http://news.ycombinator.com/leaders&gt; (leaders) * a: &lt;http://news.ycombinator.com/jobs&gt; (jobs) * a: &lt;http://news.ycombinator.com/submit&gt; (submit) * a: &lt;http://news.ycombinator.com/x?fnid=JKhQjfU7gW&gt; (login) * a: &lt;http://news.ycombinator.com/vote?for=1094578&amp;dir=up&amp;whence=%6e%65%77%73&gt; () * a: &lt;http://www.readwriteweb.com/archives/facebook_gets_faster_debuts_homegrown_php_compiler.php?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+readwriteweb+%28ReadWriteWeb%29&amp;utm_content=Twitter&gt; (Facebook speeds up PHP) * a: &lt;http://news.ycombinator.com/user?id=mcxx&gt; (mcxx) * a: &lt;http://news.ycombinator.com/item?id=1094578&gt; (9 comments) * a: &lt;http://news.ycombinator.com/vote?for=1094649&amp;dir=up&amp;whence=%6e%65%77%73&gt; () * a: &lt;http://groups.google.com/group/django-developers/msg/a65fbbc8effcd914&gt; ("Tough. Django produces XHTML.") * a: &lt;http://news.ycombinator.com/user?id=andybak&gt; (andybak) * a: &lt;http://news.ycombinator.com/item?id=1094649&gt; (3 comments) * a: &lt;http://news.ycombinator.com/vote?for=1093927&amp;dir=up&amp;whence=%6e%65%77%73&gt; () * a: &lt;http://news.ycombinator.com/x?fnid=p2sdPLE7Ce&gt; (More) * a: &lt;http://news.ycombinator.com/lists&gt; (Lists) * a: &lt;http://news.ycombinator.com/rss&gt; (RSS) * a: &lt;http://ycombinator.com/bookmarklet.html&gt; (Bookmarklet) * a: &lt;http://ycombinator.com/newsguidelines.html&gt; (Guidelines) * a: &lt;http://ycombinator.com/newsfaq.html&gt; (FAQ) * a: &lt;http://ycombinator.com/newsnews.html&gt; (News News) * a: &lt;http://news.ycombinator.com/item?id=363&gt; (Feature Requests) * a: &lt;http://ycombinator.com&gt; (Y Combinator) * a: &lt;http://ycombinator.com/w2010.html&gt; (Apply) * a: &lt;http://ycombinator.com/lib.html&gt; (Library) * a: &lt;http://www.webmynd.com/html/hackernews.html&gt; () * a: &lt;http://mixpanel.com/?from=yc&gt; () </code></pre> </div> <div> <div> <h2><a href="http://jsoup.org/cookbook">Cookbook 目錄 </a></h2> <h3>入門</h3> <ol start="1"> <li><a href="http://www.open-open.com/jsoup/parsing-a-document.htm">解析和遍歷一個html文檔</a></li></ol> <h3>輸入</h3> <ol start="2"> <li><a href="http://www.open-open.com/jsoup/parse-document-from-string.htm">解析一個html字符串</a></li> <li><a href="http://www.open-open.com/jsoup/parse-body-fragment.htm">解析一個body片斷</a></li> <li><a href="http://www.open-open.com/jsoup/load-document-from-url.htm">從一個URL加載一個Document對象</a></li> <li><a href="http://www.open-open.com/jsoup/load-document-from-file.htm">根據一個文件加載Document對象</a></li></ol> <h3>數據抽取</h3> <ol start="6"> <li><a href="http://www.open-open.com/jsoup/dom-navigation.htm">使用dom方法來遍歷一個Document對象</a></li> <li><a href="http://www.open-open.com/jsoup/selector-syntax.htm">使用選擇器語法來查找元素</a></li> <li><a href="http://www.open-open.com/jsoup/attributes-text-html.htm">從元素集合抽取屬性、文本和html內容</a></li> <li><a href="http://www.open-open.com/jsoup/working-with-urls.htm">URL處理</a></li> <li>程序示例:獲取所有鏈接</li></ol> <h3> 數據修改 </h3> <ol start="11"> <li><a href="http://www.open-open.com/jsoup/set-attributes.htm">設置屬性值</a></li> <li><a href="http://www.open-open.com/jsoup/set-html.htm">設置元素的html內容</a></li> <li><a href="http://www.open-open.com/jsoup/set-text.htm">設置元素的文本內容</a></li></ol> <h3>HTML清理</h3> <ol start="14"> <li><a href="http://www.open-open.com/jsoup/whitelist-sanitizer.htm">消除不受信任的html (來防止xss攻擊)</a></li></ol></div></div></div> <div><b>jsoup</b> HTML parser: copyright ? 2009 - 2011 <a href="http://www.open-open.com/"><b>Jonathan Hedley</b></a></div></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>

                              哎呀哎呀视频在线观看