简体   繁体   English

Google如何在搜索引擎结果页面上呈现结果

[英]How does Google render it's results on the Search engine results page

I've first noticed that the results are not in the HTML received from the server therefore I opened Dev Tools and started looking at the other files that my browser downloaded. 我首先注意到结果不是来自服务器的HTML,因此我打开了开发工具并开始查看浏览器下载的其他文件。

I've noticed that there was only one xhr request named gcosuc and no json ( nor xml or other data files downloaded) therefore I thought the code was embedded in the JS itself. 我注意到只有一个名为gcosuc xhr请求,没有json (也没有下载xml或其他数据文件),因此我认为代码已嵌入JS本身。

I then searched all the .js files downloaded by chrome and still I could not find where the search results came from. 然后,我搜索了chrome下载的所有.js文件,但仍然找不到搜索结果的来源。

The I thought that the search results might be inside and iframe element and because of this they are not shown in Dev Tools. 我认为搜索结果可能在iframe元素内部,因此,它们不会显示在开发工具中。 With this hypothesis in mind I looked at the HTML generated by the JS after the DOM was loaded thinking that the result might be embedded in an iframe and again I was wrong. 考虑到这一假设,我查看了加载DOM后由JS生成的HTML,以为结果可能会嵌入到iframe而我又错了。

Does anyone have any idea how Google gets and renders it's search results? 有谁知道Google如何获取和呈现其搜索结果?

As well as I've been able to figure out, it is all done using JavaScript and rendered dynamically as you scroll. 我已经弄清楚了,所有这些操作都使用JavaScript完成,并在滚动时动态呈现。

Google+ works similarly. Google+的工作方式与此类似。 Only what you see on the screen is actually on the DOM and it all disappears as you scroll. 实际上,只有在屏幕上看到的内容才在DOM上,并且在滚动时全部消失。

If you are trying to screen scrape the results, I would recommend rendering into a browser and looking at the resulting DOM. 如果您试图通过屏幕抓取结果,则建议渲染到浏览器中并查看生成的DOM。 I use Chromium. 我使用铬。

Made a quick try, and it's indeed an AJAX request. 快速尝试,这确实是AJAX请求。 The URI is /s and it passes GET parameters, including what you've search. URI是/s ,它传递GET参数,包括您搜索的内容。

The response is some kind of awkward JSON that includes text, styles, and some JS. 响应是某种尴尬的JSON,其中包括文本,样式和一些JS。 It's like JSON objects, but separated by this chars: /*""*/ 它就像JSON对象,但由以下字符分隔: /*""*/

Here's an example (word wrapped because lines are really long): 这是一个示例(自动换行,因为行很长):

回应范例

Edit I add the DevTools requests made by Google: 编辑我添加了Google提出的DevTools请求:

XHR请求

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

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