Java 类org.jsoup.Connection.Response 实例源码

项目:ripme    文件:TwodgalleriesRipper.java   
private void login() throws IOException {
    Response resp = Http.url(this.url).response();
    cookies = resp.cookies();
    String ctoken = resp.parse().select("form > input[name=ctoken]").first().attr("value");

    Map<String,String> postdata = new HashMap<>();
    postdata.put("user[login]", new String(Base64.decode("cmlwbWU=")));
    postdata.put("user[password]", new String(Base64.decode("cmlwcGVy")));
    postdata.put("rememberme", "1");
    postdata.put("ctoken", ctoken);

    resp = Http.url("http://en.2dgalleries.com/account/login")
               .referrer("http://en.2dgalleries.com/")
               .cookies(cookies)
               .data(postdata)
               .method(Method.POST)
               .response();
    cookies = resp.cookies();
}
项目:ripme    文件:HentaifoundryRipper.java   
@Override
public Document getFirstPage() throws IOException {
    Response resp = Http.url("http://www.hentai-foundry.com/").response();
    cookies = resp.cookies();
    resp = Http.url("http://www.hentai-foundry.com/?enterAgree=1&size=1500")
               .referrer("http://www.hentai-foundry.com/")
               .cookies(cookies)
               .response();
    // The only cookie that seems to matter in getting around the age wall is the phpsession cookie
    cookies.putAll(resp.cookies());
    sleep(500);
    resp = Http.url(url)
               .referrer("http://www.hentai-foundry.com/")
               .cookies(cookies)
               .response();
    cookies.putAll(resp.cookies());
    return resp.parse();
}
项目:ripme    文件:FlickrRipper.java   
/**
 * Login to Flickr.
 * @return Cookies for logged-in session
 * @throws IOException
 */
@SuppressWarnings("unused")
private Map<String,String> signinToFlickr() throws IOException {
    Response resp = Jsoup.connect("http://www.flickr.com/signin/")
                        .userAgent(USER_AGENT)
                        .followRedirects(true)
                        .method(Method.GET)
                        .execute();
    Document doc = resp.parse();
    Map<String,String> postData = new HashMap<>();
    for (Element input : doc.select("input[type=hidden]")) {
        postData.put(input.attr("name"),  input.attr("value"));
    }
    postData.put("passwd_raw",  "");
    postData.put(".save",   "");
    postData.put("login",   new String(Base64.decode("bGVmYWtlZGVmYWtl")));
    postData.put("passwd",  new String(Base64.decode("MUZha2V5ZmFrZQ==")));
    String action = doc.select("form[method=post]").get(0).attr("action");
    resp = Jsoup.connect(action)
                .cookies(resp.cookies())
                .data(postData)
                .method(Method.POST)
                .execute();
    return resp.cookies();
}
项目: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    文件:SchoolNoticeModel.java   
@Override
        protected void onPostExecute(Response response) {
            super.onPostExecute(response);
            if (response != null) {
                String body = response.body();
                if (!body.contains(context.getResources().getString(R.string.login_educational_administration_system))) {
                    // TODO 获取成功,保存到本地
//                    LogUtils.d(body);
                    Article article = gson.fromJson(body, Article.class);
                    if (article != null) {
                        onLoadCallback.onSuccess(article);
                    }else{
                        onLoadCallback.onFailed(Constant.Connect.ERROR);
                    }
                } else {
                    onLoadCallback.onFailed(Constant.Connect.ERROR);
                }
            } else {
                onLoadCallback.onFailed(Constant.Network.Network_ERROR);
            }
            onLoadCallback.onLoadComplete();
        }
项目:CoolQ_Java_Plugin    文件:WebUtil.java   
/**
 * 根据URL和请求类型获取请求结果,用于跨域请求
 * @param url
 * @param urlType POST OR GET
 * @return
 */
public static String getUrlResult(String url,String urlType){
    Method method = null;
    if(urlType!= null && !"".equals(urlType) && urlType.equalsIgnoreCase("post")){
        method = Method.POST;
    }else{
        method = Method.GET;
    }
    Response resp = null;
    try {
        resp = Jsoup.connect(url).userAgent("Chrome").timeout(5000).ignoreContentType(true).method(method).execute();
    } catch (IOException e) {
        log.error(WebUtil.class,e);
    }
    if(resp == null){
        return "error";
    }else{
        return resp.body();
    }
}
项目:CoolQ_Java_Plugin    文件:WebUtil.java   
/**
     * okhttpclient 发送get请求
     * @param url 网址
     * @throws Exception
     */
    public static String get(String url) throws Exception {
        Request request = new Request.Builder()
                .url(url)
                .build();

        okhttp3.Response response = okHttpClientThreadLocal.get().newCall(request).execute();
        if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

//      Headers responseHeaders = response.headers();
//      for (int i = 0; i < responseHeaders.size(); i++) {
//          System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
//      }

//      System.out.println(response.body().string());
        return response.body().string();
    }
项目:edline-api    文件:Edline.java   
/**
 * Parses main page of Edline for school, name, and classes
 * @param src
 */

public static ArrayList<Course> parseClasses(Response res) {
    String src = res.body();
    school = src.substring(src.indexOf("<title>") + 7, src.indexOf("</title>") - 11); 
    System.out.println("Attending School: " + school);

    int magicNum = src.indexOf("class=\"ed-studentName notranslate\" tabindex=\"-1\">") + 49;
    name = src.substring(magicNum, src.indexOf("</a>", magicNum));
    System.out.println("Name: " + name);

    Document doc = Jsoup.parse(src.substring(src.indexOf("<div type=\"menu\" title=\"My Classes"), src.indexOf("<div type=\"menu\" title=\"My Content\"")));

    int i = 0;
    do {
        courseList.add(new Course(doc.select("div#myClasses"+i).attr("title"), doc.select("div#myClasses"+i).attr("action"), res));
        i++;
    } while (!doc.select("div#myClasses"+i).attr("title").equals(""));

    System.out.println("Class List: " + courseList);

    return courseList;
}
项目:Crosslinks    文件:SiteReader.java   
public Document getDocument(String url) throws IOException, InterruptedException  {
    int attempts = 0;
    Document doc = null;
    while (attempts++ < getDocumentRetry) {
        try {
            Connection connection = Jsoup.connect(url);
            for (Entry<String, String> cookie : cookies.entrySet()) {
                connection.cookie(cookie.getKey(), cookie.getValue());
            }
            Response response = connection.timeout(getDocumentTimeout).execute();
            cookies.putAll(response.cookies());
            doc = response.parse();
            break;
        }
        catch (java.net.SocketTimeoutException ex) {
            LOG.info("Trying " + url + " one more time... " + attempts);
            Thread.sleep(getDocumentSleep);
        }
    }
    return doc;
}
项目:JabRefAutocomplete    文件:ScienceDirect.java   
public BibtexEntry extract(String url) {
    try {
        Document doc = Jsoup.connect(url).get();
        Element form = doc.select("form[name=exportCite]").first();
        Connection con = Jsoup.connect("http://www.sciencedirect.com" + form.attr("action"));
        for(Element hidden : form.select("input[type=hidden]"))
            con.data(hidden.attr("name"), hidden.attr("value"));
        con.data("zone", "exportDropDown");
        con.data("citation-type", "BIBTEX");
        con.data("format", "cite-abs");
        con.data("export", "Export");
        con.method(Method.POST);
        Response res = con.execute();
        return BibtexParser.singleFromString(res.body());
    } catch (Exception e) {
        Log.error(e, "Error extracting the url: " + url);
    }
    return null;
}
项目:JabRefAutocomplete    文件:IEEE.java   
public BibtexEntry extract(String url) {
    try {
        Connection con = Jsoup.connect("http://ieeexplore.ieee.org/xpl/downloadCitations");
        String id = url.substring(url.indexOf("arnumber=")+9);
        int index = id.indexOf('&');
        if(index>0)
            id = id.substring(0, index);
        con.data("recordIds", id);
        con.data("citations-format","citation-abstract");
        con.data("download-format", "download-bibtex");
        con.method(Method.POST);
        Response res = con.execute();
        return BibtexParser.singleFromString(res.body().replace("<br>", ""));
    } catch (Exception e) {
        Log.error(e, "Error extracting the url: " + url);
    }
    return null;
}
项目:JabRefAutocomplete    文件:SpringerLink.java   
public BibtexEntry extract(String url) {
    try {
        String biburl = url.replace("http://link.springer.com", "http://link.springer.com/export-citation");
        biburl += ".bib";
        Connection con = Jsoup.connect(biburl);
        con.userAgent("Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0");
        con.timeout(10000);
        Response res = con.execute();
        BibtexEntry bib = BibtexParser.singleFromString(res.body());
        if(bib != null)
            extractWebInfo(url, bib);
        return bib;
    } catch (Exception e) {
        Log.error(e, "Error extracting the url: " + url);
    }
    return null;
}
项目:nthu-cis    文件:EDocument.java   
public EDocument login() {
    Response resp = null;

    try {
        resp = SimpleHTTPUtils.httpRequestRaw(this.url,
                SimpleHTTPUtils.METHOD_GET);
    } catch (Exception e) {
        //
    }

    if (resp != null) {
        this.cookies = (HashMap<String, String>) resp.cookies();

        login2();
    }

    return this;
}
项目:kite-spring-hbase-example    文件:WebPageSnapshotService.java   
/**
 * Fetch the web page from the URL, parse the HTML to populate the metadata
 * required by WebPageSnapshotModel, and return the constructed
 * WebPageSnapshotModel.
 * 
 * @param url
 *          The URL to fetch the web page from
 * @return The WebPageSnapshotModel
 * @throws IOException
 *           Thrown if there's an issue fetching the web page.
 */
private WebPageSnapshotModel fetchWebPage(String url) throws IOException {
  long fetchTime = System.currentTimeMillis();
  Connection connection = Jsoup.connect(url);
  Response response = connection.execute();
  long postFetchTime = System.currentTimeMillis();
  int timeToFetch = (int) (postFetchTime - fetchTime);

  Document doc = response.parse();
  String destinationUrl = response.url().toString();
  String title = doc.title();
  String description = getDescriptionFromDocument(doc);
  List<String> keywords = getKeywordsFromDocument(doc);
  List<String> outlinks = getOutlinksFromDocument(doc);

  return WebPageSnapshotModel.newBuilder().setUrl(destinationUrl)
      .setFetchedAtRevTs(Long.MAX_VALUE - fetchTime)
      .setSize(doc.html().length()).setFetchedAt(fetchTime)
      .setFetchTimeMs(timeToFetch).setTitle(title)
      .setDescription(description).setKeywords(keywords)
      .setOutlinks(outlinks).setContent(doc.html()).build();
}
项目:wakclient    文件:JsoupDataService.java   
public Element getModulesPage() throws IOException {
    Connection conn = connect(BASE_URL + "/notenabfrage_bc.html",
            Connection.Method.GET, true);

    Response response = fetchPage(conn);

    String html = response.body();
    String regex = "<input type=\"hidden\" name=\"id\" value=\"(.*?)\">";
    String id = Utils.match(regex, html);

    Map<String, String> data = new HashMap<String, String>();
    data.put("id", id);
    data.put("Passwort", password);

    conn.url(BASE_URL + "/index.php");
    conn.method(Connection.Method.POST);
    conn.data(data);

    return conn.post();
}
项目:cast-any    文件:HttpActivity.java   
protected Document doInBackground(String... urls) {
    Log.d(LOG_TAG, "doInBackground, url=" + urls[0]);
    try {
        Response resp = Jsoup.connect(urls[0])
                .header("Authorization", "Basic " + base64login).timeout(30 * 1000)
                .method(Method.GET).execute();
        if (resp.contentType().contains("text/html")) {
            Log.d(LOG_TAG, "New directory");
            currentUrl = urls[0];
            return resp.parse();
        } else {
            Log.d(LOG_TAG, "UnsupportedContentType");
            return null;
        }
    } catch (UnsupportedMimeTypeException me) {
        Log.d(LOG_TAG, "UnsupportedMimeTypeException");
        return null;
    } catch (Exception e) {
        Log.d(LOG_TAG, "Other Exception");
        this.exception = e;
        return null;
    }
}
项目:cast-any    文件:WebActivity.java   
protected Document doInBackground(String... urls) {
    try {
        Response resp = Jsoup
                .connect(urls[0])
                .timeout(10 * 1000)
                .cookie("pianhao",
                        "%7B%22qing%22%3A%22super%22%2C%22qtudou%22%3A%22null%22%2C%22qyouku%22%3A%22null%22%2C%22q56%22%3A%22null%22%2C%22qcntv%22%3A%22null%22%2C%22qletv%22%3A%22null%22%2C%22qqiyi%22%3A%22null%22%2C%22qsohu%22%3A%22null%22%2C%22qqq%22%3A%22null%22%2C%22qku6%22%3A%22null%22%2C%22qyinyuetai%22%3A%22null%22%2C%22qtangdou%22%3A%22null%22%2C%22qxunlei%22%3A%22null%22%2C%22qfunshion%22%3A%22null%22%2C%22qsina%22%3A%22null%22%2C%22qpptv%22%3A%22null%22%2C%22xia%22%3A%22ask%22%2C%22pop%22%3A%22no%22%2C%22open%22%3A%22no%22%7D")
                .method(Method.GET).execute();

        return resp.parse();
    } catch (UnsupportedMimeTypeException me) {

        return null;
    } catch (Exception e) {
        this.exception = e;
        return null;
    }
}
项目:ScheduleWidgetProject    文件:GetWebPageAsync.java   
@Override
protected String doInBackground(Void... params)
{
    String html = null;

    try
    {
        Response response = Jsoup.connect(ASUPORTAL_URL_WITH_PARAMETERS).timeout(ConnectTimeoutMs).execute();
        html = response.parse().html();

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

    return html;
}
项目:ripme    文件:EroShareRipper.java   
@Override
public Document getFirstPage() throws IOException {
    String urlToDownload = this.url.toExternalForm();
    Response resp = Http.url(urlToDownload.replace("eroshare.com", "eroshae.com"))
                        .ignoreContentType()
                        .response();

    return resp.parse();
}
项目:ripme    文件:EroShareRipper.java   
public static List<URL> getURLs(URL url) throws IOException{

        Response resp = Http.url(url)
                            .ignoreContentType()
                            .response();

        Document doc = resp.parse();

        List<URL> URLs = new ArrayList<>();
        //Pictures
        Elements imgs = doc.getElementsByTag("img");
        for (Element img : imgs) {
            if (img.hasClass("album-image")) {
                String imageURL = img.attr("src");
                imageURL = "https:" + imageURL;
                URLs.add(new URL(imageURL));
            }
        }
        //Videos
        Elements vids = doc.getElementsByTag("video");
        for (Element vid : vids) {
            if (vid.hasClass("album-video")) {
                Elements source = vid.getElementsByTag("source");
                String videoURL = source.first().attr("src");
                URLs.add(new URL("https:" + videoURL));
            }
        }

        return URLs;
    }
项目:ripme    文件:AerisdiesRipper.java   
@Override
public Document getFirstPage() throws IOException {
    if (albumDoc == null) {
        Response resp = Http.url(url).response();
        cookies.putAll(resp.cookies());
        albumDoc = resp.parse();
    }
    return albumDoc;
}
项目:ripme    文件:EightmusesRipper.java   
@Override
public Document getFirstPage() throws IOException {
    if (albumDoc == null) {
        Response resp = Http.url(url).response();
        cookies.putAll(resp.cookies());
        albumDoc = resp.parse();
    }
    return albumDoc;
}
项目:ripme    文件:FuraffinityRipper.java   
public String getDescription(String page) {
    try {
        // Fetch the image page
        Response resp = Http.url(page)
                .referrer(this.url)
                .response();
        cookies.putAll(resp.cookies());

        // Try to find the description
        Elements els = resp.parse().select("td[class=alt1][width=\"70%\"]");
        if (els.size() == 0) {
            logger.debug("No description at " + page);
            throw new IOException("No description found");
        }
        logger.debug("Description found!");
        Document documentz = resp.parse();
        Element ele = documentz.select("td[class=alt1][width=\"70%\"]").get(0); // This is where the description is.
        // Would break completely if FurAffinity changed site layout.
        documentz.outputSettings(new Document.OutputSettings().prettyPrint(false));
        ele.select("br").append("\\n");
        ele.select("p").prepend("\\n\\n");
        logger.debug("Returning description at " + page);
        String tempPage = Jsoup.clean(ele.html().replaceAll("\\\\n", System.getProperty("line.separator")), "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
        return documentz.select("meta[property=og:title]").attr("content") + "\n" + tempPage; // Overridden saveText takes first line and makes it the file name.
    } catch (IOException ioe) {
        logger.info("Failed to get description " + page + " : '" + ioe.getMessage() + "'");
        return null;
    }
}
项目:ripme    文件:SankakuComplexRipper.java   
@Override
public Document getFirstPage() throws IOException {
    if (albumDoc == null) {
        Response resp = Http.url(url).response();
        cookies.putAll(resp.cookies());
        albumDoc = resp.parse();
    }
    return albumDoc;
}
项目:ripme    文件:EromeRipper.java   
@Override
public Document getFirstPage() throws IOException {
    Response resp = Http.url(this.url)
                        .ignoreContentType()
                        .response();

    return resp.parse();
}
项目:ripme    文件:EromeRipper.java   
public static List<URL> getURLs(URL url) throws IOException{

        Response resp = Http.url(url)
                            .ignoreContentType()
                            .response();

        Document doc = resp.parse();

        List<URL> URLs = new ArrayList<>();
        //Pictures
        Elements imgs = doc.getElementsByTag("img");
        for (Element img : imgs) {
            if (img.hasClass("album-image")) {
                String imageURL = img.attr("src");
                imageURL = "https:" + imageURL;
                URLs.add(new URL(imageURL));
            }
        }
        //Videos
        Elements vids = doc.getElementsByTag("video");
        for (Element vid : vids) {
            if (vid.hasClass("album-video")) {
                Elements source = vid.getElementsByTag("source");
                String videoURL = source.first().attr("src");
                URLs.add(new URL(videoURL));
            }
        }

        return URLs;
    }
项目:ripme    文件:ZizkiRipper.java   
@Override
public Document getFirstPage() throws IOException {
    if (albumDoc == null) {
        Response resp = Http.url(url).response();
        cookies.putAll(resp.cookies());
        albumDoc = resp.parse();
    }
    return albumDoc;
}
项目:ripme    文件:DeviantartRipper.java   
/**
 * If largest resolution for image at 'thumb' is found, starts downloading
 * and returns null.
 * If it finds a larger resolution on another page, returns the image URL.
 * @param thumb Thumbnail URL
 * @param page Page the thumbnail is retrieved from
 * @return Highest-resolution version of the image based on thumbnail URL and the page.
 */
private String smallToFull(String thumb, String page) {
    try {
        // Fetch the image page
        Response resp = Http.url(page)
                            .referrer(this.url)
                            .cookies(cookies)
                            .response();
        cookies.putAll(resp.cookies());
        Document doc = resp.parse();
        Elements els = doc.select("img.dev-content-full");
        String fsimage = null;
        // Get the largest resolution image on the page
        if (els.size() > 0) {
            // Large image
            fsimage = els.get(0).attr("src");
            logger.info("Found large-scale: " + fsimage);
            if (fsimage.contains("//orig")) {
                return fsimage;
            }
        }
        // Try to find the download button
        els = doc.select("a.dev-page-download");
        if (els.size() > 0) {
            // Full-size image
            String downloadLink = els.get(0).attr("href");
            logger.info("Found download button link: " + downloadLink);
            HttpURLConnection con = (HttpURLConnection) new URL(downloadLink).openConnection();
            con.setRequestProperty("Referer",this.url.toString());
            String cookieString = "";
            for (Map.Entry<String, String> entry : cookies.entrySet()) {
                cookieString = cookieString + entry.getKey() + "=" + entry.getValue() + "; ";
            }
            cookieString = cookieString.substring(0,cookieString.length() - 1);
            con.setRequestProperty("Cookie",cookieString);
            con.setRequestProperty("User-Agent", USER_AGENT);
            con.setInstanceFollowRedirects(true);
            con.connect();
            int code = con.getResponseCode();
            String location = con.getURL().toString();
            con.disconnect();
            if (location.contains("//orig")) {
                fsimage = location;
                logger.info("Found image download: " + location);
            }
        }
        if (fsimage != null) {
            return fsimage;
        }
        throw new IOException("No download page found");
    } catch (IOException ioe) {
        try {
            logger.info("Failed to get full size download image at " + page + " : '" + ioe.getMessage() + "'");
            String lessThanFull = thumbToFull(thumb, false);
            logger.info("Falling back to less-than-full-size image " + lessThanFull);
            return lessThanFull;
        } catch (Exception e) {
            return null;
        }
    }
}
项目:MMDownloader    文件:Downloader.java   
/**
 * Jsoup을 이용한 HTML 코드 파싱.
 * @param eachArchiveAddress 실제 만화가 담긴 아카이브 주소
 * @return 성공하면 html 코드를 리턴
 */
private String getHtmlPageJsoup(String eachArchiveAddress) throws Exception {
    System.out.print("고속 연결 시도중 ... ");

    // pageSource = Html코드를 포함한 페이지 소스코드가 담길 스트링, domain = http://wasabisyrup.com <-마지막 / 안붙음!
    String pageSource = null;

    // POST방식으로 아예 처음부터 비밀번호를 body에 담아 전달
    Response response = Jsoup.connect(eachArchiveAddress)
        .userAgent(UserAgent.getUserAgent())
        .header("charset", "utf-8")
        .header("Accept-Encoding", "gzip") //20171126 gzip 추가
        .data("pass", PASSWORD)
        .followRedirects(true)
        .execute();

    Document preDoc = response.parse(); //받아온 HTML 코드를 저장

    // <div class="gallery-template">이 만화 담긴 곳.
    if(preDoc.select("div.gallery-template").isEmpty()) {
        throw new Exception("Jsoup Parsing Failed");
    }
    else { // 만약 Jsoup 파싱 시 내용 있으면 성공
        pageSource = preDoc.toString();
    }

    System.out.println("성공");
    return pageSource; //성공 시 html코드 리턴
}
项目:Shadbot    文件:NetUtils.java   
public static Response getResponse(String url) throws IOException {
    return Jsoup.connect(url)
            .userAgent(Config.USER_AGENT)
            .timeout(Config.DEFAULT_TIMEOUT)
            .ignoreContentType(true)
            .ignoreHttpErrors(true)
            .execute();
}
项目:EducationalAdministrationSystem    文件:SchoolNoticeModel.java   
@Override
protected Response doInBackground(Integer... integers) {

    String json = FileUtils.getStringFromFile(context, Constant.Response.COOKIES_FILE_NAME);
    Cookies cookies = gson.fromJson(json, Cookies.class);
    Map<String, String> cookiesMap = new HashMap<>();
    ArrayList<Cookies.Cookie> cookieArrayList = cookies.getCookies();
    for (Cookies.Cookie cookie : cookieArrayList) {
        cookiesMap.put(cookie.getCookieKey(), cookie.getCookieValue());
    }
    return HttpUtils.getSchoolNotice(cookiesMap, integers[0]);
}
项目:JWTCrawler    文件:LoginJWC.java   
private void loginJWC() {
    Response res = null;
    try {
        res = Jsoup.connect(loginUri).data("xh", this.stuNum).data("sfzh", this.idCard).timeout(0).execute();
    } catch (IOException e) {
        e.printStackTrace();
    }
    this.cookies = res.cookies();
}
项目:crawler-jsoup-maven    文件:TestApiOfConnect.java   
public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
//        Connection connection = Jsoup.connect("http://bluetata.com");

//        // connection.data("aaa","ccc");  // 这是重点
//
//        connection.header("Content-Type", "application/json; charset=UTF-8");  // 这是重点
//
//        connection.header("Accept", "text/plain, */*; q=0.01");  
//
//        connection.timeout(15000);  
//
//        //String body = "{\"CategoryType\":\"SiteHome\",\"ParentCategoryId\":0,\"CategoryId\":808,\"PageIndex\":2,\"TotalPostCount\":4000,\"ItemListActionName\":\"PostList\"}"; 
//
//        //connection.requestBody(body);  
//
//        Document document = connection.post();


        String jsonBody = "{\"name\":\"ACTIVATE\",\"value\":\"E0010\"}";

        Connection connection = Jsoup.connect("http://bluetata.com/")
                .userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
                .referrer("http://bluetata.com/")
                .header("Content-Type", "application/json; charset=UTF-8")
                .header("Accept", "text/plain, */*; q=0.01")
                .header("Accept-Encoding", "gzip,deflate,sdch")
                .header("Accept-Language", "es-ES,es;q=0.8")
                .header("Connection", "keep-alive")
                .header("X-Requested-With", "XMLHttpRequest")
                .requestBody(jsonBody)
                .maxBodySize(100)
                .timeout(1000 * 10)
                .method(Connection.Method.POST);

        Response response = connection.execute();


    }
项目:firstSpider    文件:AddressCatcher.java   
private Map<String, String> loginer(String name, String password) throws IOException, Exception {
    trustAllHttpsCertificates();
    HostnameVerifier hv = (String urlHostName, SSLSession session) -> {
        System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
        return true;
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    String url = "https://ice.xjtlu.edu.cn/login/index.php";
    Connection con = Jsoup.connect(url).timeout(50000);//获取连接
    Response rs = con.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586").execute();//获取响应

    Document d1 = Jsoup.parse(rs.body());
    Map<String, String> info = new HashMap<>();
    Elements el = d1.getElementsByClass("form-input");
    Elements nameBox = el.select("[name = username]");
    nameBox.attr("value", name);
    Elements passBox = el.select("[name = password]");
    passBox.attr("value", password);
    info.put(nameBox.attr("name"), nameBox.attr("value"));
    info.put(passBox.attr("name"), passBox.attr("value"));
    Connection con2 = Jsoup.connect(url).timeout(30000);
    Response login = con2.ignoreContentType(true).method(Method.POST).data(info).cookies(rs.cookies()).execute();

    Map<String, String> map = login.cookies();
    if (map.size() > 0) {
        System.out.println("Successfully login on ice. 已成功登陆ice。");
        return map;
    } else {
        return null;
    }
}
项目:firstSpider    文件:AddressCatcher.java   
public Map<String, String> getCourse() {

        Connection con3 = Jsoup.connect("http://ice.xjtlu.edu.cn/my/index.php?mynumber=-2").timeout(300000);
        Response visit = null;
        Document d2 = null;
        Elements courseTitles = null;
        try {
            visit = con3.ignoreContentType(true).method(Method.GET).cookies(session).execute();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        if (visit != null) {
            d2 = Jsoup.parse(visit.body());
        }
        if (d2 != null) {
           // courseTitles = d2.getElementsByClass("title").select("a");     For 15-16 Edition
             courseTitles = d2.getElementsByClass("coursebox").select("h3");   // For 16-17 Edition
        }
        Map<String, String> courseMap = new TreeMap();
        for (Element ele : courseTitles) {
            // courseMap.put(ele.attr("title"), ele.attr("href"));           For 15-16 Edition
            courseMap.put(ele.select("a").attr("title"), ele.select("a").attr("href"));    // For 16-17 Edition
        }
        this.courseMap = courseMap;
        return courseMap;

    }
项目:JavaSkype    文件:WebConnector.java   
private Response sendRequest(Method method, String apiPath, boolean absoluteApiPath, String... keyval) throws IOException {
  String url = absoluteApiPath ? apiPath : SERVER_HOSTNAME + apiPath;
  Connection conn = Jsoup.connect(url).maxBodySize(100 * 1024 * 1024).timeout(10000).method(method).ignoreContentType(true).ignoreHttpErrors(true);
  logger.finest("Sending " + method + " request at " + url);
  if (skypeToken != null) {
    conn.header("X-Skypetoken", skypeToken);
  } else {
    logger.fine("No token sent for the request at: " + url);
  }
  conn.data(keyval);
  return conn.execute();
}