復制代碼 代碼如下:
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
復制代碼 代碼如下:
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();
復制代碼 代碼如下:
MatchCollection TitleMatchs = Regex.Matches(reader.ReadToEnd(), @"發表評論</a></p></div><divbody"">([/s/S]*?)</div><divshare"">", RegexOptions.IgnoreCase | RegexOptions.Multiline);
foreach (Match NextMatch in TitleMatchs)
{
s += "<br>" + NextMatch.Groups[1].Value;
TextBox1.Text += "/n" + NextMatch.Groups[1].Value;
}
新聞熱點
疑難解答
圖片精選