简体   繁体   English

Java jsoup检查按钮

[英]Java jsoup checking button

I am trying to check whether a page contains next page to sroll. 我正在尝试检查页面是否包含要滚动的下一页。 The idea is basic: get the current link, remove the index at the end and then put new index, try to connect to the new link, if it throws IOException that means it does not have next button so that can be scrolled. 这个想法很基本:获取当前链接,在末尾删除索引,然后放置新索引,尝试连接到新链接,如果它抛出IOException则意味着它没有下一个按钮,因此可以滚动。 Here is my code, and the problem it returns false even to the links that Jsoup can connect: 这是我的代码,它的问题甚至返回到Jsoup可以连接的链接,也返回false:

public boolean checkNextButton(String linkToCheck) throws IOException {

        boolean containsNextButton = true;
        try {
            //Here I am trying to connect to a link which is actually available but it still returns false
            Document doc = Jsoup.connect(turnToNextPage(linkToCheck)).get();
            specific.setPageChangeRate(specific.getPageChangeRate() - 1);
            //Set back the counter to the previous one
        } catch (IOException e) {

            containsNextButton = false;
        }
        System.out.println("The page contains next button: " + containsNextButton);
        return containsNextButton;
    }

Solution provided by Pshemo : Pshemo提供的解决方案:

It is hard to tell what exactly went wrong without more details. 如果没有更多细节,很难说出到底出了什么问题。

Are you able to access resource from linkToCheck via browser? 您是否可以通过浏览器从linkToCheck访问资源? Did you need to log-in on that site first (maybe try accessing it via incognito mode to see if it is available for anyone without creating an account). 您是否需要首先登录该网站(也许尝试通过隐身模式访问它,以查看是否有人无需创建帐户即可使用它)。

Other problem could be that some servers allow only specific browsers and they try to recognize them by using user-agent header browsers send, or if server is creating temporary session you may need to pass cookies from previous connection. 另一个问题可能是某些服务器仅允许特定的浏览器,并且它们尝试使用用户代理标头浏览器发送来识别它们,或者如果服务器正在创建临时会话,则可能需要传递来自先前连接的cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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