{"id":71654,"date":"2026-06-10T11:05:09","date_gmt":"2026-06-10T03:05:09","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/?p=71654"},"modified":"2026-06-10T11:05:09","modified_gmt":"2026-06-10T03:05:09","slug":"%e5%88%b6%e4%bd%9c%e5%ae%89%e5%8d%93app%e6%8a%93%e5%8f%96%e7%bd%91%e9%a1%b5%e6%95%b0%e6%8d%ae%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/appkaifa\/71654.html","title":{"rendered":"\u5236\u4f5c\u5b89\u5353app\u6293\u53d6\u7f51\u9875\u6570\u636e\u4ecb\u7ecd"},"content":{"rendered":"<p>\u5236\u4f5c\u5b89\u5353app\u6293\u53d6\u7f51\u9875\u6570\u636e\u9700\u8981\u4e86\u89e3\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n<p>1. \u786e\u5b9a\u6570\u636e\u6765\u6e90\u7684\u7f51\u9875URL\uff0c\u786e\u5b9a\u9700\u8981\u6293\u53d6\u7684\u6570\u636e\u5b57\u6bb5\uff1b<\/p>\n<p>2. \u5206\u6790\u7f51\u9875\u7ed3\u6784\uff0c\u786e\u5b9a\u9700\u8981\u7528\u5230\u7684\u89e3\u6790\u5668\uff1b<\/p>\n<p>3. \u4f7f\u7528\u5b89\u5353\u5f00\u53d1\u5de5\u5177\uff08\u5982Android Studio\uff09\u521b\u5efa\u65b0\u9879\u76ee\uff1b<\/p>\n<p>4. \u7f16\u5199\u4ee3\u7801\uff0c\u4f7f\u7528HTTP\u8bf7\u6c42\u83b7\u53d6\u7f51\u9875\u6570\u636e\u5e76\u89e3\u6790\uff1b<\/p>\n<p>5. \u5c06\u89e3\u6790\u540e\u7684\u6570\u636e\u5c55\u793a\u5728\u5e94\u7528\u754c\u9762\u4e0a\u3002<\/p>\n<p>\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u8be6\u7ec6\u4ecb\u7ecd\u4e00\u4e0b\u8fd9\u51e0\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n<p>1. \u786e\u5b9a\u6570\u636e\u6765\u6e90\u7684\u7f51\u9875URL\uff0c\u786e\u5b9a\u9700\u8981\u6293\u53d6\u7684\u6570\u636e\u5b57\u6bb5<\/p>\n<p>\u5728\u6211\u4eec\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u9700\u8981\u786e\u5b9a\u6211\u4eec\u9700\u8981\u4ece\u54ea\u4e2a\u7f51\u9875\u6293\u53d6\u54ea\u4e9b\u6570\u636e\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u6211\u4eec\u9700\u8981\u5148\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u8be5\u7f51\u9875\uff0c\u7136\u540e\u53f3\u952e\u67e5\u770b\u7f51\u9875\u6e90\u4ee3\u7801\uff0c\u627e\u5230\u6211\u4eec\u9700\u8981\u6293\u53d6\u7684\u6570\u636e\u5728\u7f51\u9875\u4e2d\u7684\u6807\u7b7e\u548c\u4f4d\u7f6e\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u8981\u4ece\u767e\u5ea6\u767e\u79d1\u4e2d\u6293\u53d6\u7535\u5f71\u300a\u6d41\u6d6a\u5730\u7403\u300b\u7684\u8bc4\u5206\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u8be5\u7f51\u9875\u6e90\u4ee3\u7801\u4e2d\u4e0e\u8bc4\u5206\u76f8\u5173\u7684\u6807\u7b7e\u548c\u4f4d\u7f6e\u3002\u5728\u767e\u5ea6\u767e\u79d1\u4e2d\uff0c\u8bc4\u5206\u6807\u7b7e\u4e3a\uff1a<\/p>\n<p>&#8220;`html<\/p>\n<p>\n<p>\n<p>\t\t<label>\u8bc4&nbsp;&nbsp;\u5206 :<\/label><\/p>\n<p>\t\t<span class=\"score\"><\/p>\n<p><p>\t\t\t<span style=\"width:77px\" class=\"starbar\"><\/span><\/p>\n<p>\t\t\t<strong>7.8<\/strong><\/p>\n<p>\t\t<\/span><\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8bc4\u5206\u6570\u636e\u4f4d<a href=\"https:\/\/www.anzhuoe.com\/\">\u5b89\u5353app\u5f00\u53d1\u5de5\u5177<\/a>\u4e8e `<strong>` \u6807\u7b7e\u5185\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u4ece\u8be5\u6807\u7b7e\u4e2d\u83b7\u53d6\u6570\u636e\u3002<\/p>\n<p><p>2. \u5206\u6790\u7f51\u9875\u7ed3\u6784\uff0c\u786e\u5b9a\u9700\u8981\u7528\u5230\u7684\u89e3\u6790\u5668<\/p>\n<p>\u5728\u6211\u4eec\u786e\u5b9a\u4e86\u9700\u8981\u6293\u53d6\u7684\u6570\u636e\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u7f51\u9875\u7ed3\u6784\u8fdb\u884c\u5206\u6790\u3002\u901a\u5e38\uff0c\u5728\u7f51\u9875\u6570\u636e\u6293\u53d6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u89e3\u6790\u7684\u6570\u636e\u662f\u5305\u542b\u5728\u7279\u5b9a\u6807\u7b7e\u5185\u7684\u6587\u672c\u6216\u94fe\u63a5\u7b49\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684\u89e3\u6790\u5668\u6765\u89e3\u6790\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<p>\u5e38\u7528\u7684\u89e3\u6790\u5668\u5305\u62ec DOM \u89e3\u6790\u5668\u3001SAX \u89e3\u6790\u5668\u548cJSON\u89e3\u6790\u5668\u7b49\u3002\u5728\u5b89\u5353\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b89\u5353\u81ea\u5e26\u7684\u89e3\u6790\u5668\u6216\u7b2c\u4e09\u65b9\u5e93\u6765\u89e3\u6790\u6570\u636e\u3002\u5bf9\u4e8e HTML \u548c XML \u6570\u636e\uff0cAndroid\u7cfb\u7edf\u63d0\u4f9b\u4e86 DOM \u89e3\u6790\u5668\u548c SAX \u89e3\u6790\u5668\u3002\u800c\u5bf9\u4e8e JSON \u6570\u636e\uff0c\u5219\u901a\u5e38\u4f7f\u7528 JSON \u89e3\u6790\u5668\u3002<\/p>\n<p>3. \u4f7f\u7528\u5b89\u5353\u5f00\u53d1\u5de5\u5177\uff08\u5982Android Studio\uff09\u521b\u5efa\u65b0\u9879\u76ee<\/p>\n<p>\u521b\u5efa\u65b0\u9879\u76ee\u7684\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\uff0c\u8fd9\u91cc\u4e0d\u505a\u8d58\u8ff0\u3002<\/p>\n<p>4. \u7f16\u5199\u4ee3\u7801\uff0c\u4f7f\u7528HTTP\u8bf7\u6c42\u83b7\u53d6\u7f51\u9875\u6570\u636e\u5e76\u89e3\u6790<\/p>\n<p>1. \u4f7f\u7528 HttpURLConnectio \u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u83b7\u53d6HTML\u5b57\u7b26\u4e32<\/p>\n<p>\u5728\u5b89\u5353\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u7f51\u7edc\u8bf7\u6c42\u6765\u83b7\u53d6\u7f51\u9875\u6570\u636e\u3002Android SDK \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\uff0c\u5305\u62ec HttpURLConnection\u3001HttpClient \u7b49\u3002\u8fd9\u91cc\u6211\u4eec\u6f14\u793a\u4f7f\u7528 HttpURLConnection \u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u7684\u65b9\u5f0f\u83b7\u53d6\u9875\u9762 HTML \u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`java<\/p>\n<p>public String getHtmlString() throws IOException {<\/p>\n<p>    URL url = new URL(mUrlString);<\/p>\n<p>    HttpURLConnection connection = (HttpURLConnection) url.openConnection();<\/p>\n<p>    connection.setRequestMethod(&#8220;GET&#8221;);<\/p>\n<p>    BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream());<\/p>\n<p>    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();<\/p>\n<p>    byte[] buffer = new byte[1024];<\/p>\n<p>    int len;<\/p>\n<p>    while ((len = inputStream.read(buffer)) != -1) {<\/p>\n<p>        outputStream.write(buffer, 0, len);<\/p>\n<p>    }<\/p>\n<p>    inputStream.close();<\/p>\n<p>    outputStream.close();<\/p>\n<p>    return outputStream.toString();<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u4f7f\u7528 Jsoup \u8fdb\u884c HTML \u89e3\u6790<\/p>\n<p>\u83b7\u53d6\u5230\u4e86\u7f51\u9875\u7684 HTML \u4ee3\u7801\uff0c\u6211\u4eec\u9700\u8981\u89e3\u6790\u51fa\u6211\u4eec\u9700\u8981\u7684\u6570\u636e\u3002Jsoup \u662f\u4e00\u6b3e\u4f18\u79c0\u7684 Java HTML \u89e3\u6790\u5668\uff0c\u5b83\u652f\u6301 DOM \u89e3\u6790\u548c CSS \u9009\u62e9\u5668\u7b49\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Jsoup \u6765\u89e3\u6790\u9875\u9762\u6570\u636e\uff1a<\/p>\n<p>&#8220;`java<\/p>\n<p>public void parseHtml(String html) {<\/p>\n<p>    Document document = Jsoup.parse(html);<\/p>\n<p>    Elements scoreElements = document.select(&#8220;span.score strong&#8221;);<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-04\/03\/16\/00715888836.jpg\" \/><\/figure>\n<\/p>\n<p>    if (scoreElements != null &amp;&amp; !scoreElements.isEmpty()) {<\/p>\n<p>        String score = scoreElements.get(0).text();<\/p>\n<p>        Log.d(TAG, &#8220;score:&#8221; + score);<\/p>\n<p>    } else {<\/p>\n<p>        Log.d(TAG, &#8220;score is null.&#8221;);<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u91cc\u4f7f\u7528 Jsoup \u7684 `select` \u65b9\u6cd5\u6765\u9009\u53d6\u8bc4\u5206\u6570\u636e\u6240\u5728\u7684\u6807\u7b7e\uff0c\u5e76\u4f7f\u7528 `text` \u65b9\u6cd5\u83b7\u53d6\u8be5\u6807\u7b7e\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n<p>5. \u5c06\u89e3\u6790\u540e\u7684\u6570\u636e\u5c55\u793a\u5728\u5e94\u7528\u754c\u9762\u4e0a<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5c06\u89e3\u6790\u540e\u7684\u6570\u636e\u5c55\u793a\u5728\u5e94\u7528\u754c\u9762\u4e0a\u3002\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Android \u539f\u751f\u7684 TextView \u7ec4\u4ef6\u6765\u5c55\u793a\u6570\u636e\uff1a<\/p>\n<p>&#8220;`java<\/p>\n<p>TextView mScoreTextView;<\/p>\n<p>public void showData(String data) {<\/p>\n<p>    mScoreTextView.setText(data);<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u5b8c\u6574\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`java<\/p>\n<p>public class MainActivity extends AppCompatActivity {<\/p>\n<p>    private static final String TAG = &#8220;MainActivity&#8221;;<\/p>\n<p>    private static final String URL = &#8220;https:\/\/baike.baidu.com\/item\/%E6%B5%81%E6%B5%AA%E5%9C%B0%E7%90%83\/21879693&#8221;;<\/p>\n<p>    private TextView mScoreTextView;<\/p>\n<p>    @Override<\/p>\n<p>    protected void onCreate(Bundle savedInstanceState) {<\/p>\n<p>        super.onCreate(savedInstanceState);<\/p>\n<p>        setContentView(R.layout.activity_main);<\/p>\n<p>        mScoreTextView = findViewById(R.id.score_text_view);<\/p>\n<p>        new Thread(new Runnable() {<\/p>\n<p>            @Override<\/p>\n<p>            public void run() {<\/p>\n<p>                try {<\/p>\n<p>                    String html = getHtmlString(URL);<\/p>\n<p>                    String score = parseHtml(html);<\/p>\n<p>                    showData(score);<\/p>\n<p>                } catch (IOException e) {<\/p>\n<p>                    e.printStackTrace();<\/p>\n<p>                }<\/p>\n<p>            }<\/p>\n<p>        }).start();<\/p>\n<p>    }<\/p>\n<p>    private String getHtmlString(String urlString) throws IOException {<\/p>\n<p>        URL url = new URL(urlString);<\/p>\n<p>        HttpURLConnection connection = (HttpURLConnection) url.openConnection();<\/p>\n<p>        connection.setRequestMethod(&#8220;GET&#8221;);<\/p>\n<p>        BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream());<\/p>\n<p>        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();<\/p>\n<p>        byte[] buffer = new byte[1024];<\/p>\n<p>        int len;<\/p>\n<p>        while ((len = inputStream.read(buffer)) != -1) {<\/p>\n<p>            outputStream.write(buffer, 0, len);<\/p>\n<p>        }<\/p>\n<p>        inputStream.close();<\/p>\n<p>        outputStream.close();<\/p>\n<p>        return outputStream.toString();<\/p>\n<p>    }<\/p>\n<p>    private String parseHtml(String html) {<\/p>\n<p>        Document document = Jsoup.parse(html);<\/p>\n<p>        Elements scoreElements = document.select(&#8220;span.score strong&#8221;);<\/p>\n<p>        if (scoreElements != null &amp;&amp; !scoreElements.isEmpty()) {<\/p>\n<p>            return scoreElements.get(0).text();<\/p>\n<p>        } else {<\/p>\n<p>            return null;<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>    private void showData<a href=\"https:\/\/www.anzhuoe.com\/\">\u5b89\u5353app<\/a>(String data) {<\/p>\n<p>        runOnUiThread(new Runnable() {<\/p>\n<p>            @Override<\/p>\n<p>            public void run() {<\/p>\n<p>                mScoreTextView.setText(data);<\/p>\n<p>            }<\/p>\n<p>        });<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u5728\u5e94\u7528\u542f\u52a8\u65f6\uff0c\u6211\u4eec\u4f1a\u65b0\u5f00\u4e00\u4e2a\u7ebf\u7a0b\u83b7\u53d6\u9875\u9762 HTML \u4ee3\u7801\uff0c\u5e76\u5728\u83b7\u53d6\u6210\u529f\u540e\u901a\u8fc7 Jsoup \u89e3\u6790\u8bc4\u5206\u6570\u636e\uff0c\u5e76\u5728\u754c\u9762\u4e0a\u5c55\u793a\u8bc4\u5206\u3002\u6700\u540e\u7684\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p>![](https:\/\/ai-studio-static-online.cdn.bcebos.com\/d0c6e26e79b54fd6b0f4d4f4c4644e26f7960d433089416eacea558423c0e312)<\/p>\n<p>        <\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5236\u4f5c\u5b89\u5353app\u6293\u53d6\u7f51\u9875\u6570\u636e\u9700\u8981\u4e86\u89e3\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u70b9\uff1a1. \u786e\u5b9a\u6570\u636e\u6765\u6e90\u7684\u7f51\u9875URL\uff0c\u786e\u5b9a\u9700\u8981\u6293\u53d6\u7684\u6570\u636e\u5b57\u6bb5\uff1b2. \u5206\u6790\u7f51\u9875\u7ed3\u6784\uff0c\u786e\u5b9a\u9700\u8981\u7528\u5230\u7684\u89e3\u6790\u5668\uff1b3. \u4f7f\u7528\u5b89\u5353\u5f00\u53d1\u5de5\u5177\uff08\u5982Android Stud<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[46368,26669,926,1051,1014],"class_list":{"0":"post-71654","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appkaifa","7":"tag-app","9":"tag-926","10":"tag-1051","11":"tag-1014"},"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/71654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=71654"}],"version-history":[{"count":1,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/71654\/revisions"}],"predecessor-version":[{"id":71689,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/71654\/revisions\/71689"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=71654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=71654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=71654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}