Jsoup爬啓信寶

這個是登錄的接口:

 

 

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class QiXinBao {
    public static Object[][] qiXinBao(int value) throws IOException {
        String companyName;
        String code1;
        String code2;
        //公司名稱、統一社會信用代碼、註冊號
        String homePage = "http://www.qixin.com/";
        //啓信寶首頁
        String loginUrl = "http://www.qixin.com/api/user/login";
        //啓信寶登錄接口
        String companyUrl;
        //公司信息地址

        Map<String,String> headers = new HashMap<>();
        headers.put("Accept","application/json, text/plain, */*");
        headers.put("Accept-Encoding","gzip, deflate");
        headers.put("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
        headers.put("Content-Type","application/json; charset=utf-8");
        headers.put("1b4872273d2048da5e29","e84c9b31cd81bda3dbcd9718a76777e15" +
                "b619ebb95379573bf91d34f6e6d4d973055ffbd96d2a670139a7cbb6408a" +
                "1344f2a77394ba0abc83f65ee4d8c3971bc");
        headers.put("X-Requested-With","XMLHttpRequest");
        headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0");
        //請求頭

        String body = "{\"acc\":\"13688888888\",\"pass\":\"000000\",\"captcha\":{\"isTrusted\":true}}";
        //請求體

        Connection.Response document = Jsoup.connect(loginUrl)
                .method(Connection.Method.POST)
                .headers(headers)
                .requestBody(body)
                .ignoreContentType(true)
                .ignoreHttpErrors(true)
                .timeout(30000)
                .execute();
        Map<String, String> cookies = document.cookies();
        //獲取cookie

        companyUrl = get(homePage, headers, cookies)
                .select(".col-md-6.col-xs-12.margin-b-1x")
                .select(".link")
                .get(value)
                .attr("abs:href");

        companyName = get(companyUrl, headers, cookies)
                .select(".font-f1.h4")
                .text();
        code1 = get(companyUrl, headers, cookies)
                .select(".table.table1.table-bordered.margin-t-1x>tbody>tr>td")
                .get(1)
                .text();
        code2 = get(companyUrl, headers, cookies)
                .select(".table.table1.table-bordered.margin-t-1x>tbody>tr>td")
                .get(5)
                .text();

        System.out.println(companyName+"\n"+code1+"\n"+code2);
        return new Object[][]{{companyName, code1, code2}};
    }

    private static Document get(String url, Map<String, String> map_1, Map<String, String> map_2)
            throws IOException {
        return Jsoup.connect(url)
                .headers(map_1)
                .cookies(map_2)
                .ignoreContentType(true)
                .ignoreHttpErrors(true)
                .timeout(30000)
                .get();
    }


}

 

 

 

發佈了50 篇原創文章 · 獲贊 28 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章