我同过这个文章网站http://www.aomenduchang123001.com的首页获取到了里面文章的标题 但是我不知道要这么做才能可以获取到文章的内容 求大神进来看看帮帮我把 我把代码发出来 大家帮我看看那里有不对的地方[C#] 纯文本查看 复制代码 string html = string.Empty;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.aomenduchang123001.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
html = reader.ReadToEnd();
reader.Close();
}
stream.Close();
}
string title = Regex.Match(html, @"<div\s*?class=""topcenter"">\s*?<ul[^>]*?>([\s\S]*?)</ul>").Groups[1].Value.Trim();
MatchCollection matches = Regex.Matches(title, @"<li>[^<]*?<a\s*?href=""([^""]*?)""[^>]*?>([^<]*?)</a>\s*?</li>");
//MatchCollection matches1 = Regex.Matches(title, @"<div class=""content"">[\s\S]*?</div>");
foreach (Match match in matches)
{
//match.Groups[1].Value是内容的url,你根据url取相应的内容;match.Groups[2].Value是标题
Console.WriteLine(match.Groups[1].Value + "\t" + match.Groups[2].Value+"\t"+match.Groups[3].Value);
richTextBox1.Text = match.Groups[1].Value.ToString();
richTextBox2.Text = match.Groups[2].Value.ToString();
|