找回密码
 快速注册
搜索
查看: 46|回复: 3

Charset detection

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-6-10 20:30 |阅读模式


例如这个网页从Google搜索到的网页摘要是中文乱码 Screenshot 2023-06-10 at 13-25-13 㛁䡀 - Google Search.png
而且Google将其语言检测为Chinese (Taiwan).
关于“语言检测”在Google的官方文档Google Search Console Help on multilingual sites 中提到:

Google uses only the visible content of your page to determine its language. We don’t use any code-level language information such as lang attributes.

Screenshot 2023-06-10 132823.png
原因为:该网页的头部charset标记为UTF-8
但实际的字符集却是GBK.
document.characterSet
输出为"UTF-8"
Screenshot 2023-06-10 134232.png
但是点击进入后,Firefox或Chrome浏览器都能显示为正确的字符集GBK,这是因为浏览器的字符集自动检测,这说明:虽然Google Chrome会检测字符集,但是Google Bot不会检测字符集. Screenshot 2023-06-10 at 13-20-15 省委改革办梳理干部保密风险防范全流程“一件事”清单.png
按Ctrl+U查看源码发现中文不能正常显示,说明浏览器在view-source页面不会自动检测字符集.但HTML注释(图中为绿色)能正常显示,说明网页源码的注释是UTF-8编码的. Screenshot 2023-06-10 133821.png

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-6-10 20:34
2023.06.10搜索本站
有120条结果 Screenshot 2023-06-10 at 13-32-06 site kuing.infinityfreeapp.com - Google Search.png
Google将其语言标记为English Screenshot 2023-06-10 133301.png

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-6-10 21:11


Users can override the developer-specified encoding inside the Content-Type header or inline like <meta charset="utf-8">, such as with Firefox's View → Text Encoding menu. This override is provided to fix incorrect developer-specified encodings that result in garbled text.

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-6-11 21:05
抱歉我在1#搞错了
这个网页的字符集就是UTF-8,不是GBK
Screenshot 2023-06-11 140230.png
检查元素发现正文使用了一种woff字体2059474917
这个字体的编码与通常不同.
  1. font-family: '2059474917','Microsoft YaHei' !important;
复制代码
取消这条CSS后,使用默认的字体显示是乱码.
Screenshot 2023-06-11 140254.png

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:28

Powered by Discuz!

× 快速回复 返回顶部 返回列表