httpclient (get) + jsoup 신분증 귀속 지 정보 획득
2343 단어 httpclientJSoupget
시간 이 있 으 면 코드 를 자세히 설명 하 겠 습 니 다. 모 르 는 것 이 있 으 면 메 시 지 를 남 겨 주세요.
테스트 사이트
http://qq.ip138.com/idsearch/
테스트 주민등록번호: 652302197607051677
Java 코드:
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Scanner;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class IdCard {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// httpclient
HttpClient client=new HttpClient();
// client
client.getHostConfiguration().setHost( "qq.ip138.com" , 80, "http" );
String url="/idsearch/index.asp";
Scanner in = new Scanner(System.in);
System.out.print(" :");
String ID=in.next();
System.out.print(ID);
String params = "action=idcard&"+"userid="+ID+"&B1=%B2%E9+%D1%AF";
HttpMethod method = getMethod(url, params);
client.executeMethod(method);
//String response = method.getResponseBodyAsString();
String response = new String(method.getResponseBodyAsString().getBytes("ISO-8859-1"));
System.out.println(response);
Document doc=Jsoup.parse(response);
//Elements Element
Elements element=doc.select("table"); // table
// table Elements tr tr[class$=alt] tr class =alt
// Elements titleName=element.select("tr[class$=alt]");
Elements titleName=element.select("tr");
for(org.jsoup.nodes.Element name:titleName){
System.out.println(name.text());
}
}
private static HttpMethod getMethod(String url,String params) throws IOException{
GetMethod get = new GetMethod(url+"?"+params);
get.releaseConnection();
return get;
}
}
결 과 는 다음 과 같 습 니 다. 작은 bug 도 있 습 니 다. 시간 이 있 으 면 고치 세 요.
전재 하 다
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
HttpClient 'GET' - 각도 단순화이봐, 친구들. 오늘 저는 API를 호출하는 Angular의 방법을 분석하고 싶습니다. 각 CRUD 작업에 대한 기사를 작성할 예정이므로 눈을 떼지 말고 팔로우하십시오! 이것이 기본이며 Angular 웹 사이트에서 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.