gpt4 book ai didi

c# - 无法使用 htmlagilitypack 从 https URL 下载 HTML 数据

转载 作者:太空狗 更新时间:2023-10-29 13:36:31 26 4
gpt4 key购买 nike

我有一个“小”问题 htmlagilitypack(HAP)。当我尝试从网站获取数据时出现此错误:

An unhandled exception of type 'System.ArgumentException' occurred inmscorlib.dll

Additional information: 'gzip' is not a supported encoding name. For information on defining a custom encoding, see the documentationfor the Encoding.RegisterProvider method.

我正在使用这段代码从网站获取数据:

HtmlWeb page = new HtmlWeb();
var url = "https://kat.cr/";
var data = page.Load(url);

在这段代码之后我得到了那个错误。我尝试了所有来自谷歌的东西,但没有任何帮助。

谁能告诉我如何解决这个问题?

谢谢

最佳答案

可以在使用HtmlWeb时拦截请求,根据自己的需要修改。

var page = new HtmlWeb()
{
PreRequest = request =>
{
// Make any changes to the request object that will be used.
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
return true;
}
};

var url = "https://kat.cr/";
var data = page.Load(url);

关于c# - 无法使用 htmlagilitypack 从 https URL 下载 HTML 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36219685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com