简体   繁体   English

Google如何隐藏搜索结果的HTML源代码?

[英]How does Google hide HTML source of search results?

When you try to view the source code of a Google search results page you just see a bunch of javascript code instead of readable text. 当您尝试查看Google 搜索结果页面的源代码时,您只会看到一堆javascript代码而不是可读文本。 How does Google do that? 谷歌如何做到这一点?

I have searched through the web but couldn't find a good explanation, only thing I found was this: http://goo.gl/FIvD6 and it is not really helpful. 我在网上搜索过但找不到一个好的解释,我发现的只有这个: http//goo.gl/FIvD6并没有什么帮助。

I am not a web developer but I just got curious. 我不是网络开发者,但我很好奇。 A brief explanation would be nice. 简短的解释会很好。 Thanks. 谢谢。

Google does that by generating the page using a pile of client side JavaScript. Google通过使用一堆客户端JavaScript生成页面来实现这一点。 It's almost certainly a side effect, not a design goal. 这几乎肯定是副作用,而不是设计目标。

Google loads additional elements via Ajax, so you won't get them if you view the source. Google通过Ajax加载其他元素,因此如果您查看源代码,则无法获取它们。 You can use something like Firebug to check the DOM elements after you make a new query. 在进行新查询后,您可以使用Firebug之类的东西来检查DOM元素。

That link actually explains it quite clearly. 该链接实际上非常清楚地解释了它。 The real point is, Google isn't "hiding" anything. 真正的问题是,谷歌并没有“隐藏”任何东西。 There is an extra layer to all of this, which is called the DOM (Document Object Model). 所有这一切都有一个额外的层,称为DOM(文档对象模型)。 When a page is requested from a web server, the web server might respond with some basic HTML and a lot of JavaScript code. 当从Web服务器请求页面时,Web服务器可能会响应一些基本HTML和大量JavaScript代码。 This response is then interpreted by your browser. 然后,您的浏览器会解释此响应。 It will load the HTML elements into the DOM, and then get started on churning through all of the JavaScript code, this JavaScript usually consists of a lot of instructions which manipulate the DOM (the in-memory representation of the page). 它将HTML元素加载到DOM中,然后开始编写所有JavaScript代码,这个JavaScript通常包含很多操作DOM的指令(页面的内存表示)。 It might load some extra data and insert new bits and pieces to display. 它可能会加载一些额外的数据并插入新的位和片段来显示。 The "browser window" if you like, renders whatever is in the DOM. 如果您愿意,可以使用“浏览器窗口”呈现DOM中的任何内容。 Which is not necessarily the same as whatever is in the original request, because of all the instructions that have run even before the page is rendered inside your "browser window". 这不一定与原始请求中的任何内容相同,因为所有指令甚至在页面呈现在“浏览器窗口”之前就已运行。

Google builds the DOM with the javascript you noted. Google使用您提到的javascript构建DOM。 It does this for a number of reasons: 这样做有很多原因:

  • Decrease the load on the server to generate each dynamic result set with HTML markup. 减少服务器上的负载以使用HTML标记生成每个动态结果集。
  • Google returns the results in a JSON feed ( example ) - pastebin. Google会在JSON Feed中返回结果( 示例 ) - pastebin。 Less processing power is required to produce the JSON response than a full HTML snippet or completely new page 生成JSON响应所需的处理能力低于完整的HTML代码段或全新的页面
  • Speed. 速度。 Assuming that the user has a decent internet connection, the speed of the pages rendering on the client side compared to the server side is negligible. 假设用户具有良好的互联网连接,与服务器端相比,客户端上的页面呈现速度可以忽略不计。

As suggested above, jump into firebug and have a look around :) 如上所述,跳进萤火虫并环顾四周:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM