如何删除错误类型没有定义构造函数

时间:2012-08-19 10:15:28

标签: c#

我正在尝试解析网页。但它给出了一个错误。请帮我。感谢。

以下是代码:

   static void myMain()
    {
        using (var client = new WebClient())
        {
            string data = client.DownloadString("http://www.google.com");
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(data);

            var nodes = doc.DocumentNode.SelectNodes("//a[@href]");
            foreach (HtmlNode link in nodes)
            {
                HtmlAttribute att = link.Attributes["href"];
                Console.WriteLine(att.Value);
            }
        }
    }

错误The type 'System.Windows.Form.HtmlDocument' has no constructors defined.我已包含HAP。

由于

1 个答案:

答案 0 :(得分:7)

更改

HtmlDocument doc = new HtmlDocument(); 

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

因为您不希望使用System.Windows.Form.HtmlDocument