用HttpWebRequest向该url发起请求,然后获得Response的代码再进行分析,保存

解决方案 »

  1.   

    分析html源代码,获取后插入到数据库
      

  2.   

    用HttpWebRequest向该url发起请求,然后获得Response的代码再进行分析,保存
      

  3.   

    如何分析别人的html源码呢?又如何运用正则表达式
      

  4.   

    有图和无图的要如何处理,是放在一起,还是分开处理,下面为分开处理
    图文链接部分:
    string yourStr = ...........;  //网页源码
    MatchCollection mc = Regex.Matches(yourStr, @"<div\s+class=""manu_elem"">\s*<div\s+class=""manu_photo"">[\s\S]*?<img\s+src='(?<img>[^']*)'[^>]*>\s*</a>\s*</div>\s*<div\s+class=""manu_name"">(\s*<[^>]*>\s*)+(?<text>[^<>]*)</a>\s*</div>", RegexOptions.IgnoreCase);
    foreach(Match m in mc)
    {
         richTextBox2.Text += m.Groups["img"].Value + "\n";  //图片地址
         richTextBox2.Text += m.Groups["text"].Value + "\n";  //文字
    }
    算了,一起处理的也给你写下吧:
    string yourStr = ............;
    MatchCollection mc = Regex.Matches(yourStr, @"(<div\s+class=""manu_elem"">\s*<div\s+class=""manu_photo"">[\s\S]*?<img\s+src='(?<img>[^']*)'[^>]*>\s*</a>\s*</div>\s*<div\s+class=""manu_name"">(\s*<[^>]*>\s*)+(?<text>[^<>]*)</a>\s*</div>|<div\s+class=""manu_"">[\s\S]*?<a\s+[^>]*>\s*(?<text>[^<>]*)</a>\s*</div>)", RegexOptions.IgnoreCase);
    foreach(Match m in mc)
    {
         richTextBox2.Text += m.Groups["img"].Value + "\n";   //没有图片部分,此字符串为""
         richTextBox2.Text += m.Groups["text"].Value + "\n";
    }文字链接部分:
    string yourStr = ................;
    MatchCollection mc = Regex.Matches(yourStr, @"<div\s+class=""manu_"">[\s\S]*?<a\s+[^>]*>\s*(?<text>[^<>]*)</a>\s*</div>", RegexOptions.IgnoreCase);
    foreach(Match m in mc)
    {
        richTextBox2.Text += m.Groups["text"].Value + "\n";
    }