这个是我的代码 我现在实现了获取文章的标题了 但是不知道这么获取文章的内容 然后才保存到txt文本上 路过的大神们帮帮我我是新手谢谢大神
[C#] 纯文本查看 复制代码 tring html = string.Empty;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.aomenduchang123004.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>");
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);
|