HTML敏捷性包不加载网址 [英] Html agility pack not loading url
本文介绍了HTML敏捷性包不加载网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的事情:
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;
}
}
}
现在,当我开始我的计划,它抛出的如果
sttement一个错误,说对象引用未设置到对象的实例。
。为什么不把它载入我的网页?我在做什么错在这里?
Now when I start my program, it throws an error on the if
sttement, saying that Object reference not set to an instance of an object.
. Why isn't it loading my page? What am I doing wrong here?
推荐答案
您正在寻找 .Load()
。
.LoadHtml()
希望给予物理HTML。你给了一个网站,请访问:
.LoadHtml()
expects to be given physical HTML. You are giving a website to go to:
HtmlWeb website = new HtmlWeb();
HtmlDocument rootDocument = website.Load("http://www.example.com");
这篇关于HTML敏捷性包不加载网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文