【问题标题】:android jsoup gets only one image src and i cant figure out whyandroid jsoup 只得到一个图像 src,我不知道为什么
【发布时间】:2016-12-10 20:20:46
【问题描述】:

我是安卓世界的新手。我使用 Jsoup 从谷歌图片收集图片链接但是我只得到第一个图片链接(谷歌徽标) 现在,我尝试了一切并阅读了https://jsoup.org/cookbook/extracting-data/example-list-links 但似乎没有任何效果,我更改了 userAgent、selector、不同的 url 但是......无论如何!任何人都知道我在哪里得到了一些愚蠢的东西?非常感谢

new Thread() {
                    public void run() {
                        Document doc;
                    try {
                            String myurl =myURL;

                                doc = Jsoup.connect(myurl)
                            .userAgent("Mozilla/5.0 (Windows NT 6.1)      AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36")
                            .get();
                            Elements images = doc.select("[src]");
                            for (Element image : images)
                                if (image.tagName().equals("img"))
                        {
                            imgSrc= image.attr("abs:src");
                        }

                        runOnUiThread( new Runnable()
                        {
                            public void run()
                            {
                                HowToImport.setText(imgSrc);
                            }
                        });

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }.start();

【问题讨论】:

    标签: java android image jsoup


    【解决方案1】:

    经过大量搜索后,我发现我得到了所有图片链接,但我只使用最后一个。所以要使用其他我需要的只是:

     Elements images = doc.getElementsByTag("img");
     Element first= images.get(1); // this line gives me the 1st element
     Element second= images.get(2); // this line gives me the 2nd element
    

    而且我还想出了一个事实,即我无法使用 Jsoup 从谷歌图像中提取图像,我只得到缩略图的 url 而不是实际的图像 url,因此我得到的图像超级小而且模糊.. 顺便说一句如我错了请纠正我! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      相关资源
      最近更新 更多