抓取html页面中的json数据
来源:互联网 发布:windows找不到文件c 编辑:程序博客网 时间:2024/05/21 17:23
遇见问题:
在开发爬虫时,我们有时需要抓取页面中的ajax的json数据。
解决方案:
采用正则表达式,高端大气上档次,重点是简洁,举个栗子:
html页面:
上面省去N行。。。。var userLogin = function(){var jsonBean = { number:"177***7495", intLoginType:"4", areaCode:"0471", isBusinessCustType:"N", identifyType:"B", userLoginType:"4", password:"", randomPass:"", noCheck:"N", isSSOLogin:"Y", sRand:"SSOLogin" };下面省去N行。。。。
正则抓取数据:
public static void praseStr() { String html = Models.readTxtFile("E:\\tmpTxt\\test0703.html"); String any ="[\\s\\S]*" ;//任何东西 StringBuffer regex = new StringBuffer(""); regex.append("(number.*)").append(any);//目标字段,下同 regex.append("(intLoginType.*)").append(any); regex.append("(areaCode.*)").append(any); regex.append("(isBusinessCustType.*)").append(any); regex.append("(identifyType.*)").append(any); regex.append("(userLoginType.*)").append(any); regex.append("(password.*)").append(any); regex.append("(randomPass.*)").append(any); regex.append("(noCheck.*)").append(any); regex.append("(isSSOLogin.*)").append(any); regex.append("(sRand.*)").append(any); Pattern p = Pattern.compile(regex.toString()); Matcher m = p.matcher(html); int countAll = m.groupCount(); StringBuffer json = new StringBuffer("{"); if(m.find()) for (int i=1;i<=countAll;i++){ json.append(m.group(i)) ; } System.out.println(json.append("}").toString() ); }
抓取结果:
{number:"177***7495",intLoginType:"4",areaCode:"0471",isBusinessCustType:"N",identifyType:"B",userLoginType:"4",password:"",randomPass:"",noCheck:"N",isSSOLogin:"Y",sRand:"SSOLogin"}
阅读全文
0 0
- 抓取html页面中的json数据
- html页面数据抓取
- 抓取HTML页面表格中的某一列数据
- java抓取HTML页面的数据(淘宝页面),
- 【数据抓取】HTML解析
- php 抓取页面数据
- html静态页面标签抓取
- Java HTML页面抓取实例
- 抓取html页面,邮箱账号
- .net中 网页抓取数据(提取html中的数据,提取table中的数据)
- 用Springmvc 返回json数据,填充html 或 jsp页面。
- 抓取网页中的数据
- 网络爬虫之php抓取json,xml,js,html示例分析及数据解析
- C#抓取页面数据汇总
- 使用JSOUP抓取页面数据
- python抓取页面数据实例
- php页面的数据抓取
- 抓取页面想要的数据
- c#实现简单的即时通讯(2)----客户端
- Access denied for user ''@'localhost' (using password: YES)错误
- 浅谈JS DDoS攻击原理与防御
- gitLab搭建
- TP的中文验证实现
- 抓取html页面中的json数据
- TabLayout的TabItem自定义
- Centos7 安装Qt
- Python 3从入门到精通2-打印语句
- NoSuchMethodError org slf4j helpers MessageFormatter format
- 209. Minimum Size Subarray Sum
- 微信模板推送-详情页跳转
- @JsonBackReference
- Java反射机制详解