/*取得script下面的JS变量*/
Elements scriptinfo = document.getElementsByTag("script").eq(21);
List list=new ArrayList();
Map PopWindowInfo = new LinkedHashMap();
/*循环遍历script下面的JS变量*/
for (Element script : scriptinfo) {
Pattern p=Pattern.compile("((impression|more_desc|address|phone:)"+".+?)(\",)");
Pattern p2=Pattern.compile("((ticket_info|bestvisittime|besttime|open_time_desc)"+".+?);");
String sss=script.data().toString();
// new JsonPathSelector("$..title").select(page.getRawText());
System.out.println(sss);
Matcher m = p.matcher(sss);//与字符串匹配
String arrq=null;
while(m.find()){
if(m.group(1).split(":\"").length>1){
arrq= m.group(1).split(":\"")[1];
}else{
arrq="";
}
PopWindowInfo.put(m.group(1).split(":\"")[0], convert(arrq));
// System.out.println(m.group(1).split(":\"")[0]+":"+new String(arrq.getBytes("ISO8859-1"), "GBK"));
System.out.println(m.group(1).split(":\"")[0]+":"+ convert(arrq));
}
Matcher m2 = p2.matcher(sss);//与字符串匹配
String arrqq=null;
String [] stt = null;
while(m2.find()){
String st="\',\\{text:\"";
if(m2.group(1).split(st).length>1){
// System.out.println(m2.group(1).split(st)[1]);
stt= m2.group(1).split(st)[1].split("\"}\\)");
if(stt.length !=0){
arrqq =stt[0];
}else{
arrqq="";
}
PopWindowInfo.put(m2.group(1).split(st)[0],convert(arrqq));
// System.out.println(m.group(1).split(":\"")[0]+":"+new String(arrq.getBytes("ISO8859-1"), "GBK"));
System.out.println(m2.group(1).split(st)[0]+":"+convert(arrqq));
}
}
}
public static String convert(String utfString){ StringBuilder sb = new StringBuilder(); int i = -1; int pos = 0; while((i=utfString.indexOf("\\u", pos)) != -1){ sb.append(utfString.substring(pos, i)); if(i+5 < utfString.length()){ pos = i+6; sb.append((char)Integer.parseInt(utfString.substring(i+2, i+6), 16)); } } return sb.toString(); }