2
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.home.com");
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), 
                                   System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();

该字符串包含该网页的整个 html,现在我想从该字符串中提取 html 标签。

我该怎么做?

4

1 回答 1

6

拥有Html Agility Pack可以轻松解析 HTML 内容。您可以在此处查看示例。

HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    HtmlAttribute att = link["href"];
    att.Value = FixLink(att);
 }
 doc.Save("file.htm");
于 2012-12-25T13:37:55.073 回答