1. 需要引用的類庫
復制代碼 代碼如下:
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
2. 獲取其他網站網頁內容的關鍵代碼
復制代碼 代碼如下:
WebRequest request = WebRequest.Create("http://目標網址.com/");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
//reader.ReadToEnd() 表示取得網頁的源碼
TextBox1.Text = reader.ReadToEnd();
3. 獲取其他網站網頁源碼之后通過{正則表達式}帥選有用信息
復制代碼 代碼如下:
MatchCollection TitleMatchs = Regex.Matches(reader.ReadToEnd(), @"發表評論/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: 表示不區分大小寫, 一般網站源碼大小寫不敏感所以取消之.
RegexOptions.Multiline: 表示對多行內容進行帥選.
4. 大功告成
不上圖了! 影響不好! 見諒見諒
文中代碼打包下載
您可能感興趣的文章:- C#實現通過程序自動抓取遠程Web網頁信息的代碼
- asp.net c# 抓取頁面信息方法介紹
- c# HttpWebRequest通過代理服務器抓取網頁內容應用介紹
- C# 抓取網頁內容的方法
- c#根據網址抓取網頁截屏生成圖片的示例
- c#實現抓取高清美女妹紙圖片
- C#抓取當前屏幕并保存為圖片的方法
- C#實現抓取和分析網頁類實例
- C#使用HtmlAgilityPack抓取糗事百科內容實例
- 基于C#實現網絡爬蟲 C#抓取網頁Html源碼
- C#抓取網頁數據 解析標題描述圖片等信息 去除HTML標簽