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(); } }