Search in sources :

Example 21 with Response

use of org.jsoup.Connection.Response in project ripme by RipMeApp.

the class TwodgalleriesRipper method login.

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();
}
Also used : Response(org.jsoup.Connection.Response) HashMap(java.util.HashMap)

Example 22 with Response

use of org.jsoup.Connection.Response in project ripme by RipMeApp.

the class WebtoonsRipper method getFirstPage.

@Override
public Document getFirstPage() throws IOException {
    Response resp = Http.url(url).response();
    cookies = resp.cookies();
    return Http.url(url).get();
}
Also used : Response(org.jsoup.Connection.Response)

Example 23 with Response

use of org.jsoup.Connection.Response in project ripme by RipMeApp.

the class ZizkiRipper method getFirstPage.

@Override
public Document getFirstPage() throws IOException {
    if (albumDoc == null) {
        Response resp = Http.url(url).response();
        cookies.putAll(resp.cookies());
        albumDoc = resp.parse();
    }
    return albumDoc;
}
Also used : Response(org.jsoup.Connection.Response)

Example 24 with Response

use of org.jsoup.Connection.Response in project crawler-jsoup-maven by bluetata.

the class GITHUBLoginApater method simulateLogin.

/**
 * @param userName 用户名
 * @param pwd 密码
 * @throws Exception
 */
public static void simulateLogin(String userName, String pwd) throws Exception {
    /* 
         * 第一次请求 
         * grab login form page first
         * 获取登陆提交的表单信息,及修改其提交data数据(login,password)
         */
    // get the response, which we will post to the action URL(rs.cookies())
    // 获取connection
    Connection con = Jsoup.connect(LOGIN_URL);
    // 配置模拟浏览器
    con.header(USER_AGENT, USER_AGENT_VALUE);
    // 获取响应
    Response rs = con.execute();
    // 转换为Dom树
    Document d1 = Jsoup.parse(rs.body());
    // 获取提交form表单,可以通过查看页面源码代码得知
    List<Element> eleList = d1.select("form");
    // 获取cooking和表单属性
    // lets make data map containing all the parameters and its values found in the form
    Map<String, String> datas = new HashMap<>();
    for (Element e : eleList.get(0).getAllElements()) {
        // 设置用户名
        if (e.attr("name").equals("login")) {
            e.attr("value", userName);
        }
        // 设置用户密码
        if (e.attr("name").equals("password")) {
            e.attr("value", pwd);
        }
        // 排除空值表单属性
        if (e.attr("name").length() > 0) {
            datas.put(e.attr("name"), e.attr("value"));
        }
    }
    /*
         * 第二次请求,以post方式提交表单数据以及cookie信息
         */
    Connection con2 = Jsoup.connect("https://github.com/session");
    con2.header(USER_AGENT, USER_AGENT_VALUE);
    // 设置cookie和post上面的map数据
    Response login = con2.ignoreContentType(true).followRedirects(true).method(Method.POST).data(datas).cookies(rs.cookies()).execute();
    // 打印,登陆成功后的信息
    System.out.println(login.body());
    // 登陆成功后的cookie信息,可以保存到本地,以后登陆时,只需一次登陆即可
    Map<String, String> map = login.cookies();
    for (String s : map.keySet()) {
        System.out.println(s + " : " + map.get(s));
    }
}
Also used : Response(org.jsoup.Connection.Response) HashMap(java.util.HashMap) Element(org.jsoup.nodes.Element) Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document)

Example 25 with Response

use of org.jsoup.Connection.Response in project crawler-jsoup-maven by bluetata.

the class JDLoginApater method main.

public static void main(String[] args) {
    // grab login form page first
    try {
        // lets make data map containing all the parameters and its values found in the form
        Map<String, String> mapParamsData = new HashMap<String, String>();
        mapParamsData.put("loginType", "f");
        mapParamsData.put("loginname", "18241141433");
        mapParamsData.put("nloginpwd", "password");
        mapParamsData.put("eid", "2QE5VJVZUBCRYD7LQZBJBTEFRNKPMQQA5OXKXNY7AAN4A3DKDTR7IN3GXHE5C6B4GTMW3Z53B4RGORB6YG5LUWF2UA");
        mapParamsData.put("fp", "ae5baf289624644fced3f921c6a3792c");
        mapParamsData.put("pubKey", "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC7kw8r6tq43pwApYvkJ5laljaN9BZb21TAIfT/vexbobzH7Q8SUdP5uDPXEBKzOjx2L28y7Xs1d9v3tdPfKI2LR7PAzWBmDMn8riHrDDNpUpJnlAGUqJG9ooPn8j7YNpcxCa1iybOlc2kEhmJn5uwoanQq+CA6agNkqly2H4j6wIDAQAB");
        mapParamsData.put("sa_token", "B68C442BE645754F33277E701208059080DD726A94A73F76DEC3053A838549C06EB7D3797CE1C5BBE7C2B2EF9CA7D4676F3D489984B517943EA13575FA80C7E73160F85EDB2705D145C52621D18B86C98B49AAF0DA97A2A7A964A78DDDA048AE592CF17C2AD8BF442AD743460B9316993DCDF5924AD8536FD4392C95A998E1C4C4EEDF76BF8FF03AAC145E449EAB889368EE1E7DA72B18881D527D9F51BAD9E2678DDEAFB33A647DD6D48B2A3BE1BC51DDC55AB1EAAEE2DE9A3CEA3702F93AAD1EC8EF740B632F5A4EC102498CDB31AF91CEA15DB3B6DF6FAC6CA31473ACC5E2CD727F80D2746F504A85379E7F3971086C13BA743F21731CEBFEC558E54E8D5D486CC3A19266E238F539A59C2F8630964981217DCC3B31B324F7DBF41FAEA47CA363904F06816BA9730B31BDD9FFA5498C1D0C36D67F315BA4F9236AC77BAFD5");
        mapParamsData.put("seqSid", "5844668515208615000");
        mapParamsData.put("uuid", "5653262a-5ef1-47c6-8ac2-427f519fdcfa");
        Response loginResponse = Jsoup.connect(LOGIN_URI).userAgent(USER_AGENT).timeout(TIMEOUT_UNIT * TIMEOUT_TIMES).data(mapParamsData).method(Method.POST).followRedirects(true).execute();
        System.out.println("Fetched login page");
        // System.out.println(loginResponse.toString());
        // get the cookies from the response, which we will post to the action URL
        Map<String, String> mapLoginPageCookies = loginResponse.cookies();
        System.out.println(mapLoginPageCookies);
        Document doc = Jsoup.connect("http://order.jd.com/center/list.action").cookies(mapLoginPageCookies).timeout(30000).get();
        System.out.println(doc.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Response(org.jsoup.Connection.Response) HashMap(java.util.HashMap) Document(org.jsoup.nodes.Document)

Aggregations

Response (org.jsoup.Connection.Response)28 Document (org.jsoup.nodes.Document)12 IOException (java.io.IOException)11 Element (org.jsoup.nodes.Element)10 HashMap (java.util.HashMap)8 URL (java.net.URL)4 Connection (org.jsoup.Connection)4 Elements (org.jsoup.select.Elements)4 ArrayList (java.util.ArrayList)3 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 ParseException (java.text.ParseException)1 LocalDate (java.time.LocalDate)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1