ASP.NET2.0网页采集方法
public string GetRegValue(string HtmlCode, string RegexString, string GroupKey, bool RightToLeft)2 {3&nbs
public string GetRegValue(string HtmlCode, string RegexString, string GroupKey, bool RightToLeft)
2 {
3 MatchCollection m;
4 Regex r;
5 if (RightToLeft == true)
6 {
7 r = new Regex(RegexString, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.RightToLeft);
8 }
9 else
10 {
11 r = new Regex(RegexString, RegexOptions.IgnoreCase | RegexOptions.Singleline);
12 }
13 m = r.Matches(HtmlCode);
14 string[] MatchValue = new string[m.Count];
15 for (int i = 0; i < m.Count; i++)
16 {
17 MatchValue[i] = m[i].Groups[GroupKey].Value;
18 }
19 if (MatchValue.Length > 0)
20 {
21 return MatchValue[0].ToString().Trim();
22 }
23 else
24 {
25 return "";
26 }
27 }
28 public string SniffwebCodeReturnList(string code, string wordsBegin, string wordsEnd)
29 {
30 try
31 {
32 ArrayList urlList = new ArrayList();
33 //string NewsTitle = "";
34 Regex regex1 = new Regex("" + wordsBegin + @"(?[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
35 for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
36 {
37 urlList.Add(match1.Groups["title"].ToString());
38 }
39 if (urlList.Count > 0)
40 {
41 return urlList[0].ToString();
42 }
43 else
44 {
45 return "";
46 }
47
48 }
49 catch
50 {
51 return "";
52
53 }
54
55 } 本文作者:佚名 来源:http://www.cnblogs.com/rainsure/
CIO之家 www.ciozj.com 微信公众号:imciow
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读