如何在 Android 应用程序中使用 Jsoup 来显示网站中的某些文本?

How to use Jsoup in an Android app to show certain text from a website?

我想学习 jsoup 并浏览了一些教程和文档,但是它们已经过时并且使用的功能不再起作用。

我了解了我们如何将网站变成文档

Document document = (Document) Jsoup.connect("https://crackwatch.com/").get();

但是之后呢?

例如,我想从此页面获取文本 Cracked 或 Uncracked:https://crackwatch.com/game/detroit-become-human

我该怎么做?请给出代码以及每一行的作用。

我正在使用 JSOUP 从 PlayStore 获取“当前版本”以强制更新应用程序,您可以从我的代码中获得帮助:

 private class ForceUpdateAsync extends AsyncTask<Void, String, String> {

        private Context context;
        private String currentVersion;
        private AppStartupThreadResponse response;

        public ForceUpdateAsync(Context context, String currentVersion, AppStartupThreadResponse response) {
            this.context = context;
            this.currentVersion = currentVersion;
            this.response = response;
        }

        @Override
        protected String doInBackground(Void... voids) {
            String newVersion = null;
            try {
                //HTML Parsing of the data coming from the url
                Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=com.vassar.unifiedapp.dmaedu&hl=en_IN")
                        .timeout(30000)
                        .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"))
                        .referrer("http://www.google.com")
                        .get();
                if (document != null) {

                    Elements element = document.getElementsContainingOwnText("Current Version");
                    for (Element ele : element) {
                        if (ele.siblingElements() != null) {
                            Elements sibElemets = ele.siblingElements();
                            for (Element sibElemet : sibElemets) {
                                newVersion = sibElemet.text();
                            }
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return newVersion;
        }