为什么我的代码显示为混乱,而事实并非如此?

发布于 2024-09-02 17:10:50 字数 1436 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小鸟爱天空丶 2024-09-09 17:10:50

Google 可能正在为您提供 ISO-8859-1。至少,这就是他们为我提供的用户代理“AppEngine-Google; (+http://code .google.com/appengine)"(urlfetch 使用)。 Content-Type 标头值为:

text/html; charset=ISO-8859-1

因此您可以使用:

result.content.decode('ISO-8859-1')

如果您检查 result.headers["Content-Type"],您的代码可以适应另一端的更改。通常,您可以将字符集(本例中为 ISO-8859-1)直接传递给 Python 解码方法。

Google is probably serving you ISO-8859-1. At least, that is what they serve me for the User-Agent "AppEngine-Google; (+http://code.google.com/appengine)" (which urlfetch uses). The Content-Type header value is:

text/html; charset=ISO-8859-1

So you would use:

result.content.decode('ISO-8859-1')

If you check result.headers["Content-Type"], your code can adapt to changes on the other end. You can generally pass the charset (ISO-8859-1 in this case) directly to the Python decode method.

寻找一个思念的角度 2024-09-09 17:10:50

如何获取我看到的 google.com?

它可能使用图像、javascript、CSS 等的相对 URL,您不会将其更改为 google 站点的绝对 URL。为了确认这一点:您的日志应该显示 404 错误(“找不到页面”),因为您“仅提供 HTML”的浏览器尝试查找您未提供的相对寻址资源。

how to get google.com that i saw ?

It's probably using relative URLs to images, javascript, CSS, etc, that you're not changing into absolute URLs into google's site. To confirm this: your logs should be showing 404 errors ("page not found") as the browser to which you're serving "just the HTML" tries locating the relative-addressed resources that you're not supplying.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文