我正在尝试解析网页。但它给出了一个错误。请帮我。感谢。
以下是代码:
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。
由于
答案 0 :(得分:7)
更改
HtmlDocument doc = new HtmlDocument();
到
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
因为您不希望使用System.Windows.Form.HtmlDocument