c# - 为什么我会收到与 WebClient 不兼容的浏览器消息?
问题描述
我正在尝试使用 WebClient 使用 .NET 抓取网页。但是我不断收到不兼容的浏览器消息。请参阅下面的 HTML 源代码(不幸的是,我无法共享链接,因为它是内部的)。不知何故,服务器认为我使用的是不兼容版本的 IE。我尝试设置用户代理,但没有任何效果。
<!--[if lt IE 10]>
<div id="incompatible_ie" style="display:block;font-family:Calibri,sans-serif;font-size:14px;text-align:center;margin:20% 0 5em;color:#777">
<div style="font-size:xx-large;margin-bottom:2em">HOME</div>
<div>Your browser is not supported by the application.<br>We recommend you use Google Chrome or IE11 without Compatibility Mode.</div>
</div>
<script>
console && console.error("Unsupported browser: Removing #root element to prevent React from loading.");
document.getElementsByTagName("body")[0].removeChild(document.getElementById("root"));
</script>
<![endif]-->
C#
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763");
string html = client.DownloadString(path);
解决方案
推荐阅读
- r - 使用 dplyr 和 tidyverse 的总和
- python - np.where 更新行值
- android - Android 10 EACCES(权限被拒绝)问题
- python-3.x - Python 3 ~ 如何使用 CSV 模块获得相同的结果
- css - Z-index 不适用于背景剪辑:文本和伪元素
- javascript - 按 2 个不同的属性对数组进行排序/分组
- linux - 在 Linux 中创建一个给定大小的文件并用用户数据模式填充它
- elasticsearch - Elasticsearch 中范围查询的奇怪行为
- azure - ADF 限制:一个管道中的 COPY 数据活动数量?
- botframework - Bot Framework 技能 - 无需身份验证即可调试