无法使用 Google App Engine 的 urlfetch 打开 Twitter

发布于 2024-08-27 06:34:40 字数 155 浏览 3 评论 0原文

我正在尝试使用 Google App Engine 的 urlFetch 服务获取 URL 并实现代理站点。像 Twitter 和 Facebook 这样的网站看起来都变形了,就好像它们缺少样式表一样,甚至 Google 也缺少 Google 徽标,但 Yahoo 打开一切正常,我不明白为什么。

I am trying to fetch URLs using Google App Engine's urlFetch service and implement a proxy site. Sites like Twitter and Facebook appear disfigured as if they are missing the stylesheet, even Google is missing the Google logo but Yahoo opens all fine, I can't understand why.

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

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

发布评论

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

评论(1

阿楠 2024-09-03 06:34:40

当您使用 urlfetch 时,它会获取页面的 HTML,而不获取图像、CSS、JavaScript 或任何其他资源。

Yahoo 看起来不错,大概是因为他们使用绝对 URL 指定图像和 CSS(例如 http://www.yahoo .com/image.png),因此当您的 urlfetch 页面显示时,它包含来自 yahoo.com 的完整图像 URL。请记住,当某人无权访问 yahoo.com 时,这些图像也不会出现在您的代理页面上。

编辑:看起来雅虎将其 CSS 内联到 HTML 页面本身,这可以解释为什么它在您获取的副本中起作用。

Google 显示没有 CSS/图像,因为它们的 CSS/图像被指定为相对 URL(例如,/image.png),而您的代理在 /image.png 处没有图像。

您必须解析 urlfetch 的页面content 来查找也需要获取和代理的图像和 CSS。只需确保处理相对 URL(如 /resource.png)以及绝对 URL(如 www.foo.com/resource.png)。

When you use urlfetch, it fetches the HTML of the page, and none of the images, CSS, JavaScript, or any other resources.

Yahoo looks fine presumably because they specify their images and CSS using absolute URLS (e.g., http://www.yahoo.com/image.png), so when your urlfetch'd page displays, it includes full image URLs from yahoo.com. Keep in mind, when someone doesn't have access to yahoo.com, those images won't appear on your proxied page either.

edit: It looks like Yahoo inlines their CSS into the HTML page itself, which would explain why it works in your fetched copy.

Google appears without CSS/images because their CSS/images are specified as relative URLs (e.g., /image.png), and your proxy doesn't have an image at /image.png

You'll have to parse the urlfetch'ed page content to find images and CSS that need to be fetched and proxied as well. Just be sure to handle relative URLs like /resource.png as well as absolute URLs like www.foo.com/resource.png.

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