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 도 있 습 니 다. 시간 이 있 으 면 고치 세 요.
전재 하 다

좋은 웹페이지 즐겨찾기