试图抓住这个Website但无法做到这一点..
它会抛出异常,消息包含Error downloading Html
C#代码
async public static Task<HtmlDocument> GetDocument()
{
HtmlDocument doc = null;
string url = "https://www.finedininglovers.com/recipes/appetizer/vegan-dishes-white-asparagus/";
try
{
HtmlWeb web = new HtmlWeb();
doc = await web.LoadFromWebAsync(url);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
return doc;
}
尝试将Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7
设置为UserAgent但仍无法正常工作
答案 0 :(得分:1)
此处创建了一个问题Link
下面的代码与github链接中提到的一样。
HtmlAgilityPack.HtmlDocument doc = null;
string url = "your_link";
HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
doc = web.Load(url);
var html = doc.DocumentNode.OuterHtml;