优秀企业网站欣赏店名设计网络直播平台搭建
优秀企业网站欣赏店名设计,网络直播平台搭建,邵阳建设银行网站是多少钱,wordpress term函数这段代码非常令人困惑.流程不合逻辑,异常处理很糟糕.像if(p#xff01; path)和if(cookys#xff01; cookies)之类的对象引用比较没有任何意义.要比较对象的内容,您需要使用equals()方法.到目前为止,我知道您希望在同一个域上的一堆后续Jsoup请求中维护cookie.在这种情况下,…这段代码非常令人困惑.流程不合逻辑,异常处理很糟糕.像if(p path)和if(cookys cookies)之类的对象引用比较没有任何意义.要比较对象的内容,您需要使用equals()方法.到目前为止,我知道您希望在同一个域上的一堆后续Jsoup请求中维护cookie.在这种情况下,您需要基本遵循以下流程Map cookies new HashMap();// First request.Connection connection1 Jsoup.connect(url1);for (Entry cookie : cookies.entrySet()) {connection1.cookie(cookie.getKey(), cookie.getValue());}Response response1 connection1.execute();cookies.putAll(response1.cookies());Document document1 response1.parse();// ...// Second request.Connection connection2 Jsoup.connect(url2);for (Entry cookie : cookies.entrySet()) {connection2.cookie(cookie.getKey(), cookie.getValue());}Response response2 connection2.execute();cookies.putAll(response2.cookies());Document document2 response2.parse();// ...// Third request.Connection connection3 Jsoup.connect(url3);for (Entry cookie : cookies.entrySet()) {connection3.cookie(cookie.getKey(), cookie.getValue());}Response response3 connection3.execute();cookies.putAll(response3.cookies());Document document3 response3.parse();// ...// Etc.这可以重构为以下方法private Map cookies new HashMap();public Document get(url) throws IOException {Connection connection Jsoup.connect(url);for (Entry cookie : cookies.entrySet()) {connection.cookie(cookie.getKey(), cookie.getValue());}Response response connection.execute();cookies.putAll(response.cookies());return response.parse();}可以用作YourJsoupWrapper jsoupWrapper new YourJsoupWrapper();Document document1 jsoupWrapper.get(url1);// ...Document document2 jsoupWrapper.get(url2);// ...Document document3 jsoupWrapper.get(url3);// ...请注意,即将推出的Jsoup 1.6.2将附带一个新的Connection#cookies(Map)方法,该方法应该使循环每次都是多余的.
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/87690.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!