2021北京积分结算名单公布,于是写了一篇Java代码,运行了两个多小时,终于所有数据都到了,如下截图所示:本着“Talkischeap,Showmethecode.”的原则,我们来看看源码第一的。源码入驻实体类。先写一个定下来的实体类,方便存储和分析。@Setter@GetterstaticclassPerson{privateintid;私有字符串编号;私有字符串名称;私人整数年;私人int月份;私营弦乐公司;私人双总分;私人双[]detailScore;Ajax请求返回HTML,这令人惊讶。直接写一个正则表达式来提取想要的数据。privatefinalstaticPatternLIST_PATTERN=Pattern.compile("
[^<]*?]*?>(\\S*?) | [^<]*?]*?>(\\S*?) | [^<]*?]*?>(\\d+)\\-(\\d+) | [^<]*?]*?>(\\S*?) | [^<]*?]*?>(\\S*?) | [^<]*?]*?>[^<]*?查看[^<]*? | [^<]*?
");privatestaticList
findPersonList()throwsInterruptedException{Stringurl="http://fuwu.rsj.beijing.gov.cn/jf2021integralpublic/settlePerson/tablePage";列表<人>personList=newArrayList<>();for(intpage=0;page<=6040;page+=10){Mapparams=newHashMap<>();params.put("姓名","");params.put("rows","10");params.put("page",Integer.toString(page));Stringresult=HttpUtils.doPost(url,params);Matchermatcher=LIST_PATTERN.matcher(result);while(matcher.find()){Personperson=newPerson();person.setNumber(matcher.group(1));person.setName(matcher.group(2));person.setYear(Integer.parseInt(matcher.group(3))));person.setMonth(Integer.parseInt(matcher.group(4)));person.setCompany(matcher.group(5));person.setTotalScore(Double.parseDouble(matcher.group(6)));person.setId(Integer.parseInt(matcher.group(7)));personList.add(person);}log.info("page:{}",page);Thread.sleep(1000);}returnpersonList;}获取积分详情Ajax请求返回积分详情也是HTML,直接写10个正则表达式提取想要的数据privatefinalstaticPattern[]DETAIL_PATTERN_ARRAY={Pattern.compile("合法稳定就业[^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("合法稳定住所 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("学历 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("学历推导(学位)累计居住和就业积分 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("创新与创业 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("工作居住区 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("tax | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("年龄 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("嘉奖 | [^<]*?]*?>([\\d\\.\\-]+)"),Pattern.compile("守法记录 | [^<]*?]*?>([\\d\\.\\-]+)"),};privatestaticvoidenrichPersonList(ListpersonList)throwsInterruptedException{Stringurl="http://fuwu.rsj.beijing.gov.cn/jf2021integralpublic/settlePerson/settlePersonDetails";for(inti=0;iparams=newHashMap<>();params.put("id",Integer.toString(person.getId()));Stringresult=HttpUtils.doPost(url,params);double[]detailScore=newdouble[DETAIL_PATTERN_ARRAY.length];for(intj=0;j
|