如何在C#中检索网页的HTML?

时间:2010-09-21 03:51:44

标签: c# .net html webpage

  

可能重复:
  How can I download HTML source in C#

我想要网页的源HTML,以便我可以在我的C#程序中解析它。

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

您可以使用.net HttpWebRequestHttpWebResponse执行此操作。请参阅下面的示例代码。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");
request.Timeout = 5000;

using (WebResponse response = (HttpWebResponse)request.GetResponse())
{
    Stream responeStream = response.GetResponseStream();

    //do something with the response stream
}

享受!