Java 类org.jsoup.Connection 实例源码

项目:Direct-File-Downloader    文件:HttpUtils.java   
public static File saveToFile(String address, String localFileName) throws IOException {
    File       file       = new File(localFileName);
    Connection connection = Jsoup.connect(address).ignoreContentType(true).ignoreHttpErrors(true);
    connection.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
    connection.timeout(10000);
    Connection.Response resultImageResponse = connection.execute();
    FileOutputStream    out                 = (new FileOutputStream(file));
    out.write(resultImageResponse.bodyAsBytes());           // resultImageResponse.body() is where the image's contents are.
    out.close();
    return file;
}
项目:WebtoonDownloadManager    文件:ManualController.java   
/**
 * 웹툰조회
 */
public void getWebtoon(String code) {

    if (!"".equals(code)) {
        CommonService cs = new CommonService();

        Connection conn = cs.getConnection(code);
        conn.timeout(5000);

        Document doc = null;

        codeInputField.setText(code);
        wDesc.setWrapText(true);

        try {

            doc = conn.get();

            String title = doc.select("title").text().split("::")[0];
            setTitle(title);

            String author = doc.select("div.detail h2 > span").text();
            wTitle.setText(title + "(" + author + ")");

            String desc = doc.select("div.detail p").text();
            wDesc.setText(desc);

            String img = doc.select("div.thumb > a img").attr("src");
            thumbnail.setImage(new Image(img, true));

        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                AlertSupport alert = new AlertSupport("웹툰코드를 입력하세요.");
                alert.alertInfoMsg(stage);
            }
        });
    }
}
项目:ripme    文件:NewsfilterRipper.java   
@Override
public void rip() throws IOException {
    String gid = getGID(this.url);
    String theurl = "http://newsfilter.org/gallery/" + gid;
    logger.info("Loading " + theurl);

    Connection.Response resp = Jsoup.connect(theurl)
        .timeout(5000)
        .referrer("")
        .userAgent(USER_AGENT)
        .method(Connection.Method.GET)
        .execute();
    Document doc = resp.parse();

    Elements thumbnails = doc.select("#galleryImages .inner-block img");
    for (Element thumb : thumbnails) {
        String thumbUrl = thumb.attr("src");
        String picUrl = thumbUrl.replace("thumbs/", "");
        addURLToDownload(new URL(picUrl));
    }

    waitForThreads();
}
项目:GoSCELE    文件:BaseProvider.java   
@Override
@Deprecated
protected List<Elements> doInBackground(String... params) {
    List<Elements> results = new ArrayList<>();
    int idx = 0;
    try {
        Connection.Response response = Jsoup.connect(url())
                .data(data())
                .method(method())
                .cookies(cookies())
                .execute();
        cookies = response.cookies();
        for (String param : params) {
            if (!TextUtils.isEmpty(param)) {
                results.add(response.parse().select(param));
            }
            publishProgress((int) ((double) (++idx / params.length)) * 100);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return results;
}
项目:sentry    文件:GameAdminService.java   
private synchronized boolean login() throws IOException {
    log.info("Authenticating to GS admin panel");
    String username = getUsername();
    String password = getPassword();
    rateLimiter.acquire(2);
    Connection.Response loginForm = Jsoup.connect(LOGIN_URL)
        .method(Connection.Method.GET)
        .userAgent(USER_AGENT)
        .execute();
    if (loginForm.statusCode() == 403) {
        log.warn("Disabling panel due to 403");
        enabled = false;
    }
    rateLimiter.acquire(2);
    Document document = Jsoup.connect(LOGIN_URL)
        .userAgent(USER_AGENT)
        .data("logout", "1")
        .data("username", username)
        .data("password", password)
        .data("query_string", "")
        .cookies(loginForm.cookies())
        .post();
    session.clear();
    session.putAll(loginForm.cookies());
    return !isLoginPage(document);
}
项目:android-url-preview    文件:LinkCrawler.java   
public static Web getWebPreviewFromURL(String url) throws IllegalArgumentException, IOException {
    Connection.Response response = null;
    Web web = null;

    response = Jsoup.connect(url)
            .userAgent("Mozilla/5.0")
            .ignoreHttpErrors(true)
            .execute();

    if (response.statusCode() != 200) {
        return null;
    }
    web = parseWeb(response);

    return web;
}
项目:UpdogFarmer    文件:SteamWebHandler.java   
/**
 * Unlock Steam parental controls with a pin
 */
private String unlockParental(String pin) {
    final String url = STEAM_STORE + "parental/ajaxunlock";
    try {
        final Map<String,String> responseCookies = Jsoup.connect(url)
                .referrer(STEAM_STORE)
                .followRedirects(true)
                .ignoreContentType(true)
                .cookies(generateWebCookies())
                .data("pin", pin)
                .method(Connection.Method.POST)
                .execute()
                .cookies();
        return responseCookies.get("steamparental");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:wulkanowy    文件:Api.java   
public Document postPageByUrl(String url, String[][] params) throws IOException {
    Connection connection = Jsoup.connect(url);

    for (String[] data : params) {
        connection.data(data[0], data[1]);
    }

    Connection.Response response = connection.cookies(getCookies())
            .followRedirects(true)
            .method(Connection.Method.POST)
            .execute();

    this.cookies.addItems(response.cookies());

    return response.parse();
}
项目:EducationalAdministrationSystem    文件:HttpUtils.java   
/**
 * 登录接口获取响应
 *
 * @param user
 * @return
 */
public static Response getLoginResponse(User user) {

    Map<String, String> map = new HashMap<>();
    map.put(Constant.Login.PARAM_USERNAME, user.getUsername());
    map.put(Constant.Login.PARAM_PASSWORD, user.getPassword());
    try {

        return Jsoup.connect(Constant.Login.LOGIN_URL)
                .data(map)
                .ignoreContentType(true)
                .method(Connection.Method.POST)
                .timeout(10000)
                .execute();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
项目:EducationalAdministrationSystem    文件:HttpUtils.java   
/**
 * 获取学校通知接口
 *
 * @param cookiesMap
 * @param index
 * @return
 */
public static Response getSchoolNotice(Map<String, String> cookiesMap, int index) {

    try {
        Connection con = Jsoup.connect(Constant.SchoolNotice.URL);
        con.ignoreContentType(true);
        Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> en = it.next();
            con = con.cookie(en.getKey(), en.getValue());
        }

        return con.method(Connection.Method.POST)
                .data(Constant.SchoolNotice.PARAM_PAGE_SIZE, "10")
                .data(Constant.SchoolNotice.PARAM_PAGE_INDEX, String.valueOf(index))
                .data(Constant.SchoolNotice.PARAM_A_TITLE, "")
                .data(Constant.SchoolNotice.PARAM_ORDER_BY_TYPE, "asc")
                .timeout(10000)
                .execute();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
项目:EducationalAdministrationSystem    文件:HttpUtils.java   
/**
 * 获取课程id
 *
 * @param cookiesMap
 * @return
 */
public static Response getCourseId(Map<String, String> cookiesMap) {

    try {
        Connection con = Jsoup.connect(Constant.CoursePraise.COURSE_URL);
        con.ignoreContentType(true);
        Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> en = it.next();
            con = con.cookie(en.getKey(), en.getValue());
        }

        return con.method(Connection.Method.GET)
                .data(Constant.CoursePraise.COURSE_URL_OTHER_PARAM, "zTreeAsyncTest")
                .data(Constant.CoursePraise.COURSE_URL_, "1507812989512")
                .timeout(10000)
                .execute();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
项目:EducationalAdministrationSystem    文件:HttpUtils.java   
public static Response getCourseInfo(Map<String, String> cookiesMap, String id, String name) {

        try {
            Connection con = Jsoup.connect(Constant.CoursePraise.COURSE_URL);
            con.ignoreContentType(true);
            Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> en = it.next();
                con = con.cookie(en.getKey(), en.getValue());
            }

            return con.method(Connection.Method.GET)
                    .data("id", id)
                    .data("name", name)
                    .data("pId", "")
                    .data("level", "0")
                    .data(Constant.CoursePraise.COURSE_URL_OTHER_PARAM, "zTreeAsyncTest")
                    .data(Constant.CoursePraise.COURSE_URL_, "1507812989512")
                    .timeout(10000)
                    .execute();

        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
项目:EducationalAdministrationSystem    文件:CoursePraiseModel.java   
@Override
protected void onPostExecute(Connection.Response response) {
    super.onPostExecute(response);
    if (response != null) {
        String body = response.body();
        if (body != null) {
            // TODO 获取成功,保存到本地
            LogUtils.d(body);
            Type listType = new TypeToken<List<Course.CourseInfo>>() {
            }.getType();
            courseInfoList = gson.fromJson(body, listType);
            // TODO 根据CourseId查询课程信息
            if (!courseInfoList.isEmpty()) {
                for (int i = 0; i < courseInfoList.size(); i++) {
                    new CoursePraiseInfoAsyncTask(context, onLoadCallback).execute(courseInfoList.get(i));
                }
            } else {
                onLoadCallback.onFailed(Constant.Connect.ERROR);
            }
        } else {
            onLoadCallback.onFailed(Constant.Connect.ERROR);
        }
    } else {
        onLoadCallback.onFailed(Constant.Network.Network_ERROR);
    }
}
项目:EducationalAdministrationSystem    文件:CoursePraiseModel.java   
@Override
protected void onPostExecute(Connection.Response response) {
    super.onPostExecute(response);
    if (response != null) {
        String body = response.body();
        if (body != null) {
            Type listType = new TypeToken<List<Course.CourseInfo>>() {
            }.getType();
            List<Course.CourseInfo> courseInfos = gson.fromJson(body, listType);
            Course course = new Course();
            course.setSchoolYear(courseName);
            course.setCourseInfoList(courseInfos);
            synchronized(locker){
                courseList.add(course);
                if(courseList.size() == courseInfoList.size()){
                    onLoadCallback.onSuccess(courseList);
                    onLoadCallback.onLoadComplete();
                }
            }
        }else{
            onLoadCallback.onFailed(Constant.Connect.ERROR);
            onLoadCallback.onLoadComplete();
        }
    }
}
项目:HouseSearch    文件:HouseController.java   
/**
 * 获取总页数,返回给前台
 * 参数
 *
 * @param cityCode 城市
 * @param minPrice 最低价格
 * @param maxPrice 最高价格
 * @return
 */
@ResponseBody
@RequestMapping(value = "/GetTotalPages", method = RequestMethod.POST)
public int GetTotalPages(String cityCode, int minPrice, int maxPrice, String area, String subway) {
    //构建URL
    String oldUrl = "http://" + cityCode + ".58.com";
    Connection conn = Jsoup.connect(oldUrl);
    int pages = 0;
    try {
        Response response = conn.method(Method.GET).execute();
        newUrl = response.url().toString() + "/pinpaigongyu/pn/";
        String nowUrl = newUrl + "1/?minprice=" + minPrice + "_" + maxPrice + area + subway;
        Document doc = Jsoup.connect(nowUrl).get();
        int listsum = Integer.valueOf(doc.getElementsByClass("listsum").select("em").text());
        pages = listsum % 20 == 0 ? listsum / 20 : listsum / 20 + 1;  //计算页数
    } catch (IOException ex) {

    }
    return pages;
}
项目:strictfp-back-end    文件:SafeCheck.java   
@Test(timeout = 6000)
public void test() throws IOException {
    Connection con = Jsoup.connect("http://localhost/api/v0/misc/safecheck").data("url",
            Base64.getEncoder().encodeToString("http://www.alphamedical02.fr/".
                    getBytes(StandardCharsets.UTF_8)))
            .timeout(8000);
    Document doc = con.get();
    assertEquals(doc.text(),"{\"data\":{\"en\":{\"buttons\":[\"Back\",\"Continue with a fully compreh" +
            "ension about the risks originated from this action\"],\"message\":\"The external link you're w" +
            "illing to access is considered dangerous by the ZeuS Tracker or Malware Domain List, and the de" +
            "velopers team cannot be certain about the safety of the source of the link.\\nWe won't take " +
            "any responsibility of the influence caused by continuing accessing this link. You may choose to " +
            "stop accessing and be navigated back to our site or continue accessing, but the risks originated" +
            " from this action would be considered on your own.\\nWARNING: The website you're willing to access" +
            " has been considered harmful by ZeuS Tracker or Malware Domain List.\"},\"zh_CN\":{\"buttons\":" +
            "[\"返回\",\"我已了解此行为所带来的风险并继续 \"],\"message\":\"此外链已被ZeuS Tracker或Malware Domain L" +
            "ist标注为危险网站,且开发团队无法保证此网站的安全性。\\n我们对继续访问此危险网站所致的后果不承担任何责任,您可以" +
            "选择返回或继续访问,但这将意味着您必须承担此行为所带来的风险。\\n警告:您所访问的网站已被ZeuS Tracker或Malwar" +
            "e Domain List确认为危险网站。\\n\"}},\"meta\":{\"code\":\"200\",\"message\":\"hazard query success\"}}");
}
项目:bboxapi-voicemail    文件:VoiceMailApi.java   
private UserInfo getUserInfo() {

        UserInfo userInfo = new UserInfo();

        try {
            Connection.Response customerInfo = Jsoup.connect(VOICEMAIL_SERVICE_URI).cookies(loadCookies()).execute();

            Document doc = customerInfo.parse();

            Elements pseudo = doc.select("input[name=pseudo]");
            Elements phoneNumber = doc.select("input[name=voip_num]");
            Elements login = doc.select("input[name=login]");
            Elements email = doc.select("input[name=email]");
            Elements uid = doc.select("input[name=uid]");

            userInfo.setPseudo((pseudo.size() > 0) ? pseudo.get(0).attr("value") : "");
            userInfo.setPhoneNumber((phoneNumber.size() > 0) ? phoneNumber.get(0).attr("value") : "");
            userInfo.setLogin((login.size() > 0) ? login.get(0).attr("value") : "");
            userInfo.setEmail((email.size() > 0) ? email.get(0).attr("value") : "");
            userInfo.setUid((uid.size() > 0) ? uid.get(0).attr("value") : "");

        } catch (IOException e) {
            e.printStackTrace();
        }
        return userInfo;
    }
项目:Library-Token-Automation    文件:Details.java   
@Override
protected Void doInBackground(Void... params) {
    try {
        Connection.Response loginform = Jsoup.connect("https://markattendance.webapps.snu.edu.in/public/application/login/login")
                .method(Connection.Method.GET)
                .validateTLSCertificates(false)
                .execute();
        page = Jsoup.connect("https://markattendance.webapps.snu.edu.in/public/application/login/loginAuthSubmit")
                .data("cookieexists", "false")
                .data("login_user_name", Netid)
                .data("login_password", pass)
                .validateTLSCertificates(false)
                .cookies(loginform.cookies())
                .post();
        page = Jsoup.connect("https://markattendance.webapps.snu.edu.in/public/application/index/summary")
                .cookies(loginform.cookies())
                .get();
        Log.d("Main", page.title());
        if (!(page.title().startsWith("Login"))) connected = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:openedt    文件:CelcatAdapter.java   
@Override
public ArrayList<Group> getGroupsList(Component c, Context context) throws IOException {
    ArrayList<Group> liste = new ArrayList<>();


    String url = c.groups_url;
    Connection conn = Jsoup.connect(url);
    Document doc = conn.get();
    for (Element e : doc.select("option[value$=.html]"))
    {
        Group groupe = new Group();
        groupe.name = e.text();
        groupe.dataSourceType = DataSourceType.CELCAT;
        groupe.dataSource = getRefactoredUrl(url)+(e.attr("value").replaceAll(".html", ".xml"));
        groupe.component = c;
        liste.add(groupe);
    }
    return liste;
}
项目:ufrgs-mobile-android    文件:LibraryConnector.java   
/**
 * Using login and password, connects a user to SABi.
 *
 * @return Map of cookies. Used to all actions after login.
 */
private Map<String, String> connectUser(String session, LibraryUserVo user) throws ConnectionErrorExecption {
    try {
        if(DebugUtils.DEBUG) Log.d(TAG, "Will connect: (" + user.userLogin + ", " + user.userPassword + ")");
        Connection.Response login = Jsoup.connect("http://sabi.ufrgs.br/F/" + session + "?func=file&file_name=login-session")
                .data("ssl_flag","Y","func","login-session","login_source","bor-info","bor_library","URS50","bor_id",user.userLogin,"bor_verification",user.userPassword,"x","0","y","0")
                .method(Connection.Method.POST)
                .timeout(60000)
                .execute();

        return login.cookies();

    } catch (IOException | NullPointerException e) {
        if(DebugUtils.ERROR) Log.e(TAG, "connectUser error: " + e.getMessage());
        throw new ConnectionErrorExecption();
    }
}
项目:printful4j    文件:OrdersApiClient.java   
@Override
public Response<Order> createANewOrder(Order order, boolean confirm, boolean updateExisting) {
    if (order == null) {
        throw new IllegalArgumentException("Order cannot be null.");
    }

    try {
        String response = LibUtils.createConnection(base64Key, "orders", configuration)
                .method(Connection.Method.POST).requestBody(LibUtils.gson.toJson(order))
                .data("confirm", String.valueOf(confirm),
                        "update_existing", String.valueOf(updateExisting))
                .execute().body();

        return createResponseFromApi(response);
    } catch (IOException e) {
        try {
            Log.e(TAG, "Error occurred while creating a new order.", e);
        } catch (Exception e1) {
            e.printStackTrace();
        }
    }

    return null;
}
项目:VTMobile    文件:Login.java   
@Override
protected Boolean doInBackground(String... params) {
    try {
        Connection.Response res = Jsoup.connect(URL_LOGIN)
                .data("user", user, "pass", password)
                .method(Connection.Method.POST)
                .timeout(6000)
                .execute();

        cookies = res.cookies();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
项目:xxl-incubator    文件:JsoupUtil.java   
/**
 * 按照规则,加载解析html
 * @param url       :加载URL
 * @param paramMap  :请求参数
 * @param cookieMap :请求cookie
 * @param ifPost    :是否使用post请求
 * @param tagMap    :解析规则[0-选择器方式、1-id方式、2-class方式、3-tag]
 * @return
 */
public static Elements loadParse(String url, Map<String, String> paramMap, Map<String, String> cookieMap,
        boolean ifPost, Map<Integer, Set<String>> tagMap) {
    if (!isUrl(url)) {
        return null;
    }
    try {
        // 请求设置
        Connection conn = Jsoup.connect(url);
        conn.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
        if (paramMap != null && !paramMap.isEmpty()) {
            conn.data(paramMap);
        }
        if (cookieMap != null && !cookieMap.isEmpty()) {
            conn.cookies(cookieMap);
        }
        conn.timeout(5000);

        // 发出请求
        Document html = null;
        if (ifPost) {
            html = conn.post();
        } else {
            html = conn.get();
        }

        // 过滤元素
        Elements resultAll = new Elements();
        if (tagMap != null && !tagMap.isEmpty()) {
            for (Entry<Integer, Set<String>> tag : tagMap.entrySet()) {
                int tagType = tag.getKey();
                Set<String> tagNameList = tag.getValue();
                if (tagNameList != null && tagNameList.size() > 0) {
                    for (String tagName : tagNameList) {
                        if (tagType == 0) {
                            Elements resultSelect = html.select(tagName);   // 选择器方式
                            resultAll.addAll(resultSelect);
                        } else if (tagType == 1) {
                            Element resultId = html.getElementById(tagName);    // 元素ID方式
                            resultAll.add(resultId);
                        } else if (tagType == 2) {
                            Elements resultClass = html.getElementsByClass(tagName);    // ClassName方式
                            resultAll.addAll(resultClass);
                        } else if (tagType == 3) {
                            Elements resultTag = html.getElementsByTag(tagName);    // html标签方式
                            resultAll.addAll(resultTag);
                        }
                    }
                }

            }

        } else {
            resultAll = html.getElementsByTag("body");
        }
        return resultAll;
    } catch (IOException e) {
        logger.error("", e);
    }

    return null;
}
项目:common    文件:UrlConnectTest.java   
@Test
public void fetchHandlesXml() throws IOException {
    // should auto-detect xml and use XML parser, unless explicitly requested the html parser
    String xmlUrl = "http://direct.infohound.net/tools/parse-xml.xml";
    Connection con = Jsoup.connect(xmlUrl);
    Document doc = con.get();
    Connection.Request req = con.request();
    assertTrue(req.parser().getTreeBuilder() instanceof XmlTreeBuilder);
    assertEquals("<xml> <link> one </link> <table> Two </table> </xml>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
项目:photometric-data-retriever    文件:NsvsPlugin.java   
@Override
public List<PhotometricData> getDataFromUrl(String url) {
    List<PhotometricData> result = new ArrayList<>();
    Document doc;
    try {
        Jsoup.connect(url).get();
        Connection.Response res = Jsoup.connect(url).execute();
        doc = Jsoup.connect("http://skydot.lanl.gov/nsvs/print_light_curve.php").cookies(res.cookies()).get();
    } catch (IOException e) {
        e.printStackTrace();
        return result;
    }
    Elements trs = doc.getElementsByTag("tr");
    trs.remove(0);
    for (Element tr : trs) {
        Double julianDate = Double.parseDouble(tr.child(0).text()) + 2450000.5;
        PhotometricData data = new PhotometricData(julianDate.toString(), tr.child(1).text(), tr.child(2).text());
        result.add(data);
    }
    return result;
}
项目:krapi-core    文件:KHttpClient.java   
private void execute(String url, Consumer<Connection> connectionConsumer) {
    Connection connection = Util.getConnection(url, this.cookies, this.referrer);
    connectionConsumer.accept(connection);

    logger.debug("Visiting {}", url);

    try {
        this.currentPage = null;
        this.currentResult = connection.execute();
        this.currentPage = this.currentResult.parse();
        this.referrer = url;
    }
    catch(IOException e) {
        logger.error("Could not open {}", url);
    }
}
项目:printful4j    文件:ShippingRateApiClient.java   
@Override
public Response<ShippingInfo> calculateShippingRates(ShippingRequest request) {
    try {
        String response = LibUtils.createConnection(base64Key, "shipping/rates", configuration)
                .method(Connection.Method.POST)
                .requestBody(LibUtils.gson.toJson(request))
                .execute().body();

        Type type = new TypeToken<Response<ShippingInfo>>() {
        }.getType();
        return LibUtils.gson.fromJson(response, type);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}
项目:CrawlerSYS    文件:WebCrawler.java   
public static Connection getConnect(String url, Map<String,String> header, Map<String,String> cookie){
        Connection con;
//      Document doc = null;
        url = url.trim();
        con = Jsoup.connect(url);
        con.ignoreContentType(true);
//      if(!url.startsWith("http:/")){
//          return null;
//      }
        if(url.split(":", 2)[0].equals("https")){
            con.validateTLSCertificates(false);
        }
        if(!(header==null||header.isEmpty())){
            for(Object key : header.keySet()){
                con.header((String) key, header.get(key));
            }
        }else{
            con.header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        }
        if(!(cookie==null||cookie.isEmpty()))
            con.cookies(cookie);
//      try {
//          doc = con.get();
//      } catch (IOException e) {
//          // TODO Auto-generated catch block
//      e.printStackTrace();logger.error("Exception",e);
//      }
        con.ignoreHttpErrors(true).ignoreContentType(true);
        return con;
    }
项目:RxRetroJsoup    文件:RxJsoup.java   
public static Observable<Connection.Response> connect(final Connection jsoupConnection) {
    return Observable.create(new ObservableOnSubscribe<Connection.Response>() {
        @Override
        public void subscribe(ObservableEmitter<Connection.Response> observableEmitter) throws Exception {
            try {
                final Connection.Response response = jsoupConnection.execute();
                observableEmitter.onNext(response);
                observableEmitter.onComplete();
            } catch (Exception e) {
                observableEmitter.onError(e);
            }
        }

    });
}
项目:guanggoo-android    文件:NewTopicTask.java   
@Override
public void run() {

    String xsrf = getXsrf();

    Map<String, String> headers = new HashMap<>();
    headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    headers.put("Content-Type", "application/x-www-form-urlencoded");

    Map<String, String> datas = new HashMap<>();
    datas.put("title", mTitle);
    datas.put("content", mContent);
    datas.put(ConstantUtil.KEY_XSRF, xsrf);

    Map<String, String> cookies = getCookies();
    if (!cookies.containsKey(ConstantUtil.KEY_XSRF)) {
        cookies.put(ConstantUtil.KEY_XSRF, xsrf);
    }

    try {
        Connection.Response res = Jsoup.connect(mUrl).cookies(cookies).headers(headers).data(datas).method(Connection.Method.POST).execute();
        if (res.statusCode() == ConstantUtil.HTTP_STATUS_200 || res.statusCode() == ConstantUtil.HTTP_STATUS_302) {
            successOnUI("发布成功");
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    failedOnUI("发布失败");
}
项目:guanggoo-android    文件:FavouriteTask.java   
@Override
public void run() {

    String xsrf = getXsrf();

    Map<String, String> headers = new HashMap<>();
    headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    headers.put("Content-Type", "application/x-www-form-urlencoded");

    Map<String, String> datas = new HashMap<>();
    datas.put(ConstantUtil.KEY_XSRF, xsrf);

    Map<String, String> cookies = getCookies();
    if (!cookies.containsKey(ConstantUtil.KEY_XSRF)) {
        cookies.put(ConstantUtil.KEY_XSRF, xsrf);
    }

    try {
        Connection.Response res = Jsoup.connect(mUrl).cookies(cookies).headers(headers).data(datas).method
                (Connection.Method.GET).execute();
        if (res.statusCode() == ConstantUtil.HTTP_STATUS_200 || res.statusCode() == ConstantUtil.HTTP_STATUS_302) {
            successOnUI("成功");
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    failedOnUI("失败");
}
项目:guanggoo-android    文件:BaseTask.java   
protected Connection getConnection(String url) {
    Connection connection = Jsoup.connect(url);

    Map<String, String> cookies = getCookies();
    if (cookies.size() > 0) {
        connection.cookies(cookies);
    }

    return connection;
}
项目:guanggoo-android    文件:CommentTask.java   
@Override
public void run() {

    String xsrf = getXsrf();

    Map<String, String> headers = new HashMap<>();
    headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    headers.put("Content-Type", "application/x-www-form-urlencoded");

    Map<String, String> datas = new HashMap<>();
    datas.put("tid", UrlUtil.getTid(mUrl));
    datas.put("content", mContent);
    datas.put(ConstantUtil.KEY_XSRF, xsrf);

    Map<String, String> cookies = getCookies();
    if (!cookies.containsKey(ConstantUtil.KEY_XSRF)) {
        cookies.put(ConstantUtil.KEY_XSRF, xsrf);
    }

    try {
        Connection.Response res = Jsoup.connect(mUrl).cookies(cookies).headers(headers).data(datas).method(Connection.Method.POST).execute();
        if (res.statusCode() == ConstantUtil.HTTP_STATUS_200 || res.statusCode() == ConstantUtil.HTTP_STATUS_302) {
            successOnUI("评论成功");
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    failedOnUI("评论失败");
}
项目:android-url-preview    文件:LinkCrawler.java   
private static Web parseWeb(Connection.Response response) throws IOException {
    Document document = response.parse();

    String imageURL = "";
    String title = "";
    String description = "";
    String url = response.url().toString();

    if (response.url().getHost().contains("twitter")) {
        title = document.select("meta[property=twitter:title]").attr("content");
        imageURL = document.select("meta[property=twitter:image]").attr("content");
        description = document.select("meta[property=twitter:description]").attr("content");

    } else if (response.url().getHost().contains("youtube")) {
        title = document.select("meta[property=title:image]").attr("content");

    } else if (response.url().getHost().contains("spotify")) {

    } else {
        title = document.select("meta[property=og:title]").attr("content");
        imageURL = document.select("meta[property=og:image]").attr("content");
        description = document.select("meta[property=og:description]").attr("content");
        url = document.select("meta[property=og:url]").attr("content");
    }

    Web web = new Web(title, url, description, imageURL);
    return web;
}
项目:UpdogFarmer    文件:SteamWebHandler.java   
public JSONArray generateNewDiscoveryQueue() throws Exception {
    final String url = STEAM_STORE + "explore/generatenewdiscoveryqueue";
    final String json = Jsoup.connect(url)
            .ignoreContentType(true)
            .referrer(STEAM_STORE)
            .followRedirects(true)
            .cookies(generateWebCookies())
            .method(Connection.Method.POST)
            .data("sessionid", sessionId)
            .data("queuetype", "0")
            .execute()
            .body();
    return new JSONObject(json).getJSONArray("queue");
}
项目:wulkanowy    文件:Api.java   
public Document getPageByUrl(String url) throws IOException {
    Connection.Response response = Jsoup.connect(url)
            .followRedirects(true)
            .cookies(getCookies())
            .execute();

    this.cookies.addItems(response.cookies());

    return response.parse();
}
项目:DailyProgrammer    文件:WebParser.java   
public Link parse() throws IOException {
    Link parent = null;

    do {
        visited.add(startUrl);

        Connection con = Jsoup.connect(startUrl).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");
        Document doc = con.get();

        Element head = doc.getElementById("firstHeading");
        Link current = new Link(startUrl, head.text());

        current.parent = parent;
        parent = current;

        Elements links = doc.getElementById("bodyContent").select("a[href]");

        for(Element link : links) {
            String url = link.absUrl("href");

            if(url.startsWith("https://en.wikipedia.org/wiki/") && url.lastIndexOf(":") == 5 && !url.contains("#")) {
                if(url.equals("https://en.wikipedia.org/wiki/Philosophy")) {
                    Link phil = new Link("https://en.wikipedia.org/wiki/Philosophy", "Philosophy");
                    phil.parent = parent;

                    return phil;
                }

                if(!visited.contains(url))
                    toVisit.add(url);
            }
        }

        startUrl = toVisit.poll();
    } while(!toVisit.isEmpty());

    return null;
}
项目:page-content-tester    文件:FetcherTest.java   
private Parameters.ParametersBuilder aValidRequest() {
    return Parameters.builder()
            .urlToFetch("http://localhost:8089/example")
            .userAgent("")
            .requestBody("")
            .referrer("")
            .cookie(Collections.emptyMap())
            .headers(Collections.emptyMap())
            .proxy(Collections.emptyMap())
            .method(Connection.Method.GET);
}