基于Jsoup的爬虫中ajax获取数据的方式(post)

来源:互联网 发布:确认域名所有权纠纷 编辑:程序博客网 时间:2024/06/10 15:49

以https://www.mynextmove.org/explore/ip为例,其中所有的操作都是用ajax的post方法获取数据

public String doPost(Map<String, String> createMap, String url)
        {  
             HttpClientUtil  httpClientUtil = new HttpClientUtil();
            String httpOrgCreateTest = url;  
            String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap,charset);  
            //System.out.println("result:"+httpOrgCreateTestRtn);
            return httpOrgCreateTestRtn;
        } 
调用的时候,需要传入一个包含请求信息的map(懂ajax的,传入的是data的内容)和要访问的url

public static void main(String[] args)
 {

         //其中score和i是循环出的东西,score是需要自己写一个计算的方法的,不另附,测试可以用030201000000代替,i的范围是1-5

         Map<String,String> createMap = new HashMap<String,String>(); 
         createMap.put("page","S6");
         createMap.put("subpage","");
         createMap.put("results","------------------------------------------------------------");
         createMap.put("scores",score);
         createMap.put("zone",i+"");
         createMap.put("maxvisit","R1");
         createMap.put("client","");
         createMap.put("random","0");
         createMap.put("accessible","0");
         createMap.put("submit_page_R1.x","54");
         createMap.put("submit_page_R1.y","16");

         String result = holland.doPost(createMap, url);

 }

P.S.返回的字符串可以是json格式,也可以是网页html

如果返回的是json格式,可以设置实体类与其对应,getset属性

阅读全文
0 0
原创粉丝点击