简体   繁体   中英

Using Jsoup to connect two URLs sequentially

i'm trying to get all images on this Category with resolution 1080 x 1920.

My Issue :

If i navigate to the site in first time ,site displays all images with all resolutions.

BUT if i want it to display only images with resolution 1080 x 1920,i should access to this Filter 1080x1920 FIRST , after that Category displays all images with the resolution i need.

What i have tried is access to Filter 1080x1920 first and get cookies to use it in Category :

@Override
        protected List<Wallpaper> doInBackground(final Integer... integers) {
            try {
                firstPage = Jsoup.connect(getResources().getString(R.string.AllRequest))
                        .method(Connection.Method.POST)
                        .execute();
                Map<String, String> Cookies = firstPage.cookies();
                doc = Jsoup.connect(URL + "?page=" + integers[0])
                        .cookies(Cookies)
                        .get();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (doc != null) {
                Elements newsHeadlines = doc.select("div.item-element");
                for (Element headline : newsHeadlines) {
                    String thumb = headline.select("a").select("img").attr("src");
                    String title = headline.select("a").select("img").attr("title");
                    Wallpaper wallpaperInfo = new Wallpaper();
                    wallpaperInfo.setThumbnails(thumb);
                    wallpaperInfo.setTitle(title);
                    urls.add(wallpaperInfo);

                }
            }
            return urls;
        }

What i want is connect to Filter 1080x1920 first, after that Category . Could you help me?

Thanks!

Solved my problem with add UserAgent

 try {
                firstPage = Jsoup.connect(getResources().getString(R.string.AllRequest)).userAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36").method(Connection.Method.GET).execute();
                Map<String, String> Cookies = firstPage.cookies();
                doc = Jsoup.connect(URL + "?page=" + integers[0]).cookies(Cookies).get();

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM