问题描述
我正在使用HTML Agility Pack从URL获取元标记。我使用的是HtmlWeb
的{{1}},但发现它花了太长时间,并认为我可以改用异步方法来提高性能。但是,当我尝试使用Load
时,会收到NullReferenceException。
使用LoadFromWebAsync
Load
使用public static MetaTags GetMetaData(string url)
{
// This works
var webGet = new HtmlWeb();
var document = webGet.Load(url);
var metaTags = document.DocumentNode.SelectNodes("//meta");
MetaTags metaInfo = new MetaTags(url);
//more code
}
LoadFromWebAsync
我正在使用此方法来获取要传递给public static async Task<MetaTags> GetMetaData(string url)
{
// This doesn't work
var webGet = new HtmlWeb();
var document = await webGet.LoadFromWebAsync(url); //breaks here
var metaTags = document.DocumentNode.SelectNodes("//meta");
MetaTags metaInfo = new MetaTags(url);
//more code
}
组件的url数据,我试图这样做:
NewsCard
为什么会出现此错误,该如何解决?
编辑: 我不确定什么是null,我在Blazor中工作,当它中断时,它退出到自创建项目以来就存在的此行上的_Host.cshtml: 。我认为这可能与尝试加载组件之前要加载的组件有关。
堆栈跟踪:
<p
@news.Title
</p>
@code {
public MetaTags news { get; set; }
protected override async Task OnInitializedAsync()
{
news = await MetaScraper.GetMetaData(" https://www.denverpost.com/2020/10/03/president-trump-fight-against-covid-19-update/");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)