博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.net处理页面的抓取数据
阅读量:4624 次
发布时间:2019-06-09

本文共 1293 字,大约阅读时间需要 4 分钟。

//要抓取数据的页面路径        string url = "http://www.scedu.net/banshi/used-car/lower-secondary-education/middle-school-list/1381286867.shtml";       //将页面上的数据转换为HTML        string html = Method.GetHtmlData(url);        //   txt_content.Text = html;        //找到需要的数据匹配正则  (?
.+?) string regex = @"
(?
.+?)"; Regex listRegex = new Regex(regex, RegexOptions.Multiline | RegexOptions.IgnoreCase); //得到匹配的数据集合 MatchCollection mc = listRegex.Matches(html); JCheng.Model.School Model = new JCheng.Model.School(); //将得到的字符串分割存进数组 string[] str = txt_content.Text.Substring(0, txt_content.Text.Length - 1).Replace("
", "").Split(','); //数据每六个为一个model类 ,如下循环添加入库。 for (int i = 0; i < str.Length - 1; ) { Model.sName = str[i]; Model.sAddress = str[i + 1]; Model.sPostCode = str[i + 2]; Model.sPhone = str[i + 3]; Model.sEmail = str[i + 4]; Model.sClass = str[i + 5]; new JCheng.BLL.School().Add(Model); i += 6; }

经常会遇到需要读取一些省市 区 县之类的信息, 数据庞大,手动输入效率太慢, 以上代码为读取的一个区县的所有中学信息的列表,抓取出来然后存到自己的数据库里面用, 很快很酷炫。 呵呵, 第一次做数据抓取, 代码肯定不是写的很好, 还是记录一下吧,希望对大家有所帮助。  

转载于:https://www.cnblogs.com/wr1437/p/3711733.html

你可能感兴趣的文章
6.10
查看>>
lcd_1602
查看>>
三年工作总结
查看>>
循环不变式证明算法的正确性
查看>>
实现算法2.15、2.16的程序(一个数组只生成一个静态链表)
查看>>
java常用设计模式
查看>>
Web开发中的网络知识(传输层)
查看>>
Shell脚本8种字符串截取方法总结
查看>>
串模式匹配——KMP算法
查看>>
贪心讲解链接
查看>>
初识MyBatis
查看>>
在线HTML编辑器Kindeditor-4.1.10简易示例
查看>>
深入浅出Windows命令——telnet
查看>>
jQuery事件与事件对象
查看>>
vim:隆重推荐括号补全插件--auto-pairs
查看>>
前端sublime的环境配置
查看>>
Linux的sed命令介绍
查看>>
WPF弹出取消确定框
查看>>
矩阵的理解——转载
查看>>
jQuery实现“弹层即消失”的最简单方法(用于提示性的弹层)
查看>>