//要抓取数据的页面路径
string url = "http://www./banshi/used-car/lower-secondary-education/middle-school-list/1381286867.shtml"; //将页面上的数据转换为HTML string html = Method.GetHtmlData(url); // txt_content.Text = html; //找到需要的数据匹配正则 (?<name>.+?) string regex = @"<font size=""2"">(?<name>.+?)</td>"; 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("<br />", "").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; } |
|
来自: 昵称10504424 > 《技术》