oje*_*jek 5 c# html-parsing html-agility-pack
我有这样的事情:
class MyTask
{
public MyTask(int id)
{
Id = id;
IsBusy = false;
Document = new HtmlDocument();
}
public HtmlDocument Document { get; set; }
public int Id { get; set; }
public bool IsBusy { get; set; }
}
class Program
{
public static void Main()
{
var task = new MyTask(1);
task.Document.LoadHtml("http://urltomysite");
if (task.Document.DocumentNode.SelectNodes("//span[@class='some-class']").Count == 0)
{
task.IsBusy = false;
return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在当我开始我的程序时,它会在ifsttement 上抛出错误,这样说Object reference not set to an instance of an object..为什么不加载我的页面?我在这做错了什么?
Arr*_*ran 18
你在找.Load().
.LoadHtml()期望获得物理HTML.您正在建立一个网站:
HtmlWeb website = new HtmlWeb();
HtmlDocument rootDocument = website.Load("http://www.example.com");
Run Code Online (Sandbox Code Playgroud)