是否可以从 Google 搜索中捕获搜索词?

Is it possible to capture search term from Google search?(是否可以从 Google 搜索中捕获搜索词?)
本文介绍了是否可以从 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=

只需从请求头解析 URL,用户使用的搜索词将在 q - 参数中.上面例子中使用的搜索词是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 header或者header可能完全丢失,所以不要根据Referer header做太认真的决定.

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 搜索中捕获搜索词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)