【问题标题】:How to use Jsoup in an Android app to show certain text from a website?如何在 Android 应用程序中使用 Jsoup 显示网站中的某些文本?
【发布时间】:2020-10-13 02:17:23
【问题描述】:

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

将网站放入文档中

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

但是之后呢?

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

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

【问题讨论】:

    标签: android android-studio jsoup


    【解决方案1】:

    我正在使用 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;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多