是否可以从Google搜索中捕获搜索字词? [英] Is it possible to capture search term from Google search?

查看:93
本文介绍了是否可以从Google搜索中捕获搜索字词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但是有可能捕获用户输入到Google搜索框中的内容,以便将其用于在我的网站的着陆页上生成动态页面?

This may be a stupid question, but is it possible to capture what a user typed into a Google search box, so that this can then be used to generate a dynamic page on the landing page on my Web site?

例如,假设有人搜索Google热狗,并且我的网站成为搜索结果链接之一。如果用户点击指向他们到我的网站的链接,是否有可能以某种方式知道或捕获Google搜索框中的热狗文本,以便我可以调用脚本来搜索我的本地数据库中的内容相关的热狗,然后显示那个?对我来说这似乎完全不可能,但我不知道。谢谢。

For example, let's say someone searches Google for "hot dog", and my site comes up as one of the search result links. If the user clicks the link that directs them to my Web site, is it possible for me to somehow know or capture the "hot dog" text from the Google search box, so that I can call a script that searches my local database for content related to hot dogs, and then display that? It seems totally impossible to me, but I don't really know. Thanks.

推荐答案

是的,这是可能的。请参阅HTTP标头 Referer 。 Referer头部将包含Google搜索结果页面的URL。

Yes, it is possible. See HTTP header Referer. The Referer header will contain URL of Google search result page.

当用户点击Google搜索结果页面上的链接时,浏览器会向您的网站发送请求类型的HTTP标头:

When user clicks a link on a Google search result page, the browser will make a request to your site with this kind of HTTP header:

Referer: http://www.google.fi/search?hl=en&q=http+header+referer&btnG=Google-search&meta=&aq=f&oq=

只需从请求标头解析网址,用户使用的搜索字词将位于 q -parameter中。上面例子中使用的搜索词是 http header referer

Just parse URL from request header, the search term used by user will be in q -parameter. Search term used in above example is "http header referer".

同样的方法通常也适用于其他搜索引擎,它们在Referer头部中只有不同类型的URL。

Same kind of approach usually works also for other search engines, they just have different kind of URL in Referer header.

回答展示了如何在PHP中实现这个功能。

This answer shows how to implement this in PHP.

Referer头文件仅适用于HTTP 1.1,但几乎涵盖有点现代的浏览器浏览器也可能会伪造Referer头文件或头文件可能完全丢失,因此请勿根据Referer头文件做出过于严重的偏见。

Referer header is only available with HTTP 1.1, but that covers just about any somewhat modern browser. Browser may also forge Referer header or the header might be missing altogether, so do not make too serious desicions based on Referer header.

这篇关于是否可以从Google搜索中捕获搜索字词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆