我网站的访问者来自搜索引擎吗? 他们的搜索词是什么?
我想根据访问者是否来自搜索引擎以不同的方式显示我的页面。 我想我正在检测搜索引擎推荐? 我还想知道用于到达我的网站的搜索词。
到目前为止我的解决方案是这样的:
1)过滤包含常见搜索引擎URL的HTTP请求引用,即http:// /www.google.com/search、http://www.bing.com/search, 或 http://search.yahoo.com/search
2) 解析查询字符串参数搜索词的引用者,例如“q=search+terms+for+my+website+go+here”
我觉得这不是最可靠的解决方案,因为它错过了不太知名的搜索引擎,并且每个搜索引擎可能有它是搜索词自己的查询字符串参数。 例如,据我所知,Google 和 Bing 的搜索词参数都是“q”,但 Yahoo 的搜索词参数是“p”。 那么像 +、- 等特殊运算符呢?
有没有更通用的方法来做到这一点? 或者是否有一个库可以帮助我处理更多搜索引擎? 我正在使用在 Tomcat 上运行的 Java,但欢迎来自任何语言和服务器设置的想法。
I'd like to display my page differently for the visitor based on if they came from a search engine or not. I guess I'm detecting search engine referrals? I'd also like to know the search terms used to arrive at my site.
My solution so far is this:
1) Filter on the HTTP request referers which contain common search engine URLs, i.e. http://www.google.com/search, http://www.bing.com/search, or http://search.yahoo.com/search
2) Parse the query string parameter of the referer for the search terms, e.g. "q=search+terms+for+my+website+go+here"
I feel this isn't the most robust solution, because it misses lesser known search engines and each search engine may have it's own query string parameter for the search terms. For example, Google's and Bing's search term parameter are both "q" but Yahoo's is "p" as far as I can tell. And what about special operators like +, -, etc.?
Is there a more general way to do this? Or is there a library that would help me handle more search engines? I'm working with Java running on Tomcat, but ideas from any language and server setup are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看这里:
http://www.gdargaud.net/Hack/Searches.html
和此处:
http://search.cpan.org/perldoc?URI::ParseSearchString
2方法略有不同,但它们涵盖了更广泛的搜索引擎及其引用字符串。
Have a look here:
http://www.gdargaud.net/Hack/Searches.html
and here:
http://search.cpan.org/perldoc?URI::ParseSearchString
2 slightly different approaches but they cover a much wider range of search engines and their referer strings.
你的方法就是你能做到的最好的。 我在 Drupal 上运行了一个类似的模块,
http://drupal.org/project/search_engine_referers
如果你看在代码中,它完全按照你所说的进行。 我认为他们还没有支持 Bing.com 的版本。
考虑到搜索市场份额的走向,如果您能处理 Google(AOL 使用 Google)、Bing 和 Yahoo,您将获得超过 90% 的搜索。 您真的需要担心其他搜索网站吗? 如果您像我一样在中国,请将 baidu.com 添加到列表中。
有一些奇怪的小搜索网站是你无法处理的。 他们每隔一段时间改变一次参数。 有些甚至使用 POST 发送查询,因此它在引荐来源网址中不可用。
Your approach is about the best you can do. I ran a similar module on Drupal,
http://drupal.org/project/search_engine_referers
If you look at the code, it does exactly what you said. I don't think they have a version supporting Bing.com yet.
Considering where the search market share is going, you get well over 90% of the searches if you can handle Google (AOL uses Google), Bing and Yahoo. Do you really need to worry about other search sites? If you are in China like I am, add baidu.com to the list.
There are weird small search sites that you just can't handle. They change their parameter once a while. Some even use POST to send the query so it's not available in referrer.
对于 PHP,您请求 $_REQUEST["HTTP_REFERRER"] 并使用一些 pregs 或 ereg 解析搜索字符串。
In case of PHP, you request the $_REQUEST["HTTP_REFERRER"] and parse the search-string with some pregs or eregs.