亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP.net(C#)從其他網(wǎng)站抓取內(nèi)容并截取有用信息的實現(xiàn)代碼

 更新時間:2011年09月24日 20:06:17   作者:  
ASP.net(C#)從其他網(wǎng)站抓取內(nèi)容并截取有用信息的實現(xiàn)代碼,需要的朋友可以參考下。
1. 需要引用的類庫
復制代碼 代碼如下:

using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

2. 獲取其他網(wǎng)站網(wǎng)頁內(nèi)容的關(guān)鍵代碼
復制代碼 代碼如下:

WebRequest request = WebRequest.Create("http://目標網(wǎng)址.com/");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
//reader.ReadToEnd() 表示取得網(wǎng)頁的源碼
TextBox1.Text = reader.ReadToEnd();

3. 獲取其他網(wǎng)站網(wǎng)頁源碼之后通過{正則表達式}帥選有用信息
復制代碼 代碼如下:

MatchCollection TitleMatchs = Regex.Matches(reader.ReadToEnd(), @"發(fā)表評論</a></p></div><div class=""body"">([\s\S]*?)</div><div class=""share"">", RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach (Match NextMatch in TitleMatchs)
{
s += "<br>" + NextMatch.Groups[1].Value;
TextBox1.Text += "\n" + NextMatch.Groups[1].Value;
}

RegexOptions.IgnoreCase: 表示不區(qū)分大小寫, 一般網(wǎng)站源碼大小寫不敏感所以取消之.

RegexOptions.Multiline: 表示對多行內(nèi)容進行帥選.
4. 大功告成
不上圖了! 影響不好! 見諒見諒
文中代碼打包下載

相關(guān)文章

最新評論