1. 需要引用的類庫
復制代碼 代碼如下:
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
2. 獲取其他網(wǎng)站網(wǎng)頁內(nèi)容的關鍵代碼
復制代碼 代碼如下:
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. 大功告成
不上圖了! 影響不好! 見諒見諒
文中代碼打包下載
您可能感興趣的文章:- C#實現(xiàn)通過程序自動抓取遠程Web網(wǎng)頁信息的代碼
- asp.net c# 抓取頁面信息方法介紹
- c# HttpWebRequest通過代理服務器抓取網(wǎng)頁內(nèi)容應用介紹
- C# 抓取網(wǎng)頁內(nèi)容的方法
- c#根據(jù)網(wǎng)址抓取網(wǎng)頁截屏生成圖片的示例
- c#實現(xiàn)抓取高清美女妹紙圖片
- C#抓取當前屏幕并保存為圖片的方法
- C#實現(xiàn)抓取和分析網(wǎng)頁類實例
- C#使用HtmlAgilityPack抓取糗事百科內(nèi)容實例
- 基于C#實現(xiàn)網(wǎng)絡爬蟲 C#抓取網(wǎng)頁Html源碼
- C#抓取網(wǎng)頁數(shù)據(jù) 解析標題描述圖片等信息 去除HTML標簽