ASP.net从其他网站抓取内容并截取有用信息
2011-10-27 10:12
537 查看
ASP.net从其他网站抓取内容并截取有用信息,1. 需要引用的类库
1 using System.Net;
2 using System.IO;
3 using System.Text;
4 using System.Text.RegularExpressions;
2. 获取其他网站网页内容的关键代码
1 WebRequest request = WebRequest.Create("/");
2 WebResponse response = request.GetResponse();
3 StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
4 //reader.ReadToEnd() 表示取得网页的源码
5 TextBox1.Text = reader.ReadToEnd();
3. 获取其他网站网页源码之后通过{正则表达式}帅选有用信息
1 MatchCollection TitleMatchs = Regex.Matches(reader.ReadToEnd(), @"发表评论</a></p></div><div class=""body"">([\s\S]*?)</div><div class=""share"">", RegexOptions.IgnoreCase | RegexOptions.Multiline);
2 foreach (Match NextMatch in TitleMatchs)
3 {
4 s += "<br>" + NextMatch.Groups[1].Value;
5 TextBox1.Text += "\n" + NextMatch.Groups[1].Value;
6 }
RegexOptions.IgnoreCase: 表示不区分大小写, 一般网站源码大小写不敏感所以取消之.
RegexOptions.Multiline: 表示对多行内容进行帅选.
1 using System.Net;
2 using System.IO;
3 using System.Text;
4 using System.Text.RegularExpressions;
2. 获取其他网站网页内容的关键代码
1 WebRequest request = WebRequest.Create("/");
2 WebResponse response = request.GetResponse();
3 StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
4 //reader.ReadToEnd() 表示取得网页的源码
5 TextBox1.Text = reader.ReadToEnd();
3. 获取其他网站网页源码之后通过{正则表达式}帅选有用信息
1 MatchCollection TitleMatchs = Regex.Matches(reader.ReadToEnd(), @"发表评论</a></p></div><div class=""body"">([\s\S]*?)</div><div class=""share"">", RegexOptions.IgnoreCase | RegexOptions.Multiline);
2 foreach (Match NextMatch in TitleMatchs)
3 {
4 s += "<br>" + NextMatch.Groups[1].Value;
5 TextBox1.Text += "\n" + NextMatch.Groups[1].Value;
6 }
RegexOptions.IgnoreCase: 表示不区分大小写, 一般网站源码大小写不敏感所以取消之.
RegexOptions.Multiline: 表示对多行内容进行帅选.
相关文章推荐
- [ 转]C#(ASP.net)从其他网站抓取内容并截取有用信息
- C#(ASP.net)从其他网站抓取内容并截取有用信息
- ASP.net(C#)从其他网站抓取内容并截取有用信息的实现代码
- [ 转]C#(ASP.net)从其他网站抓取内容并截取有用信息
- ASP.net(C#)从其他网站抓取内容并截取有用信息的实现代码
- C#(ASP.net)从其他网站抓取内容并截取有用信息
- asp.net如何抓取其他网站的内容
- asp.net开发网站时指定或截取标题字数的方法和内容页多关键字切分的方法
- SEO_ASP.net SEO优化(包含URL地址重写\viewState移动和压缩至服务器\SEO信息XML生成_根据URL地址重写文件)\web网站内容压缩 源码公开.本人授权可使用于商业项目。
- 用asp.net实现远程获取其他网站页面指定内容
- [转]用asp.net实现远程获取其他网站页面指定内容
- 【.Net码农】用asp.net实现远程获取其他网站页面指定内容
- C# asp.net 抓取需要登录的网页内容 抓取asp.net登录验证的网站
- 获取网站中其他网页的内容(摘抄自《精通ASP.Net 2.0企业级项目开发》)
- ASP.net C#获取其他网站的页面内容
- 读书笔记:《精通ASP.Net 2.0企业级项目开发》—— 获取网站中其他网页的内容
- 用asp.net实现远程获取其他网站页面指定内容
- 用asp.net实现远程获取其他网站页面指定内容
- ASP.NET 2.0 中Adrotator控件用于管理网站的广告显示内容
- asp.net 网站模板怎么用,就是16aspx上面下下来的模板,里面有个sln文件,其他全是文件夹的东西