如何找出htmlagilitypack.htmldocument的ContentType



im试图确定HtmlAgility.HtmlDocument的内容类型。任何想法??

        HtmlWeb web = new HtmlWeb();
        var hDocument = web.Load(/*string*/ url);

如果可能的话,我想知道如何找出hDocument的ContentType,或者是否有任何工作。谢谢

基本上您想要的是httpwebresponse对象,要使用hap获得此功能。

var web = new HtmlAgilityPack.HtmlWeb();
var tcs = new TaskCompletionSource<HttpWebResponse>();
web.PostResponse = delegate(HttpWebRequest request, HttpWebResponse response)
{
    tcs.SetResult(response);
};
var  document = web.Load("http://stackoverflow.com/");
var httpWebResponse = await tcs.Task;
var contentType = httpWebResponse.ContentType

我已经有一段时间没有这样做了,没有机会测试此代码,但应该适合您想要的内容。

从HTML敏捷包HTMLWEB获取HTTPWebresponsehttps://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebresponse.contenttype?view=netframework-4.7.2

最新更新