在Javascript中从Google搜索中提取关键字 [英] Extract keyword from Google search in Javascript
问题描述
我想从Google搜索的网址中提取搜索关键字(例如关键字car: http://www.google.com/webhp?hl=en#sclient=psy&hl = en& site = webhp& source = hp& q = car& aq ...(此处汽车位于q =和& aq
之间,但我注意到令牌可能会改变[& ie而不是& aq])。
I'd like to extract from the url of a Google search the keyword of the search (e.g. for the keyword "car" : http://www.google.com/webhp?hl=en#sclient=psy&hl=en&site=webhp&source=hp&q=car&aq ... (here car is between "q=" and "&aq" but I noticed that the tokens might change ["&ie" instead of "&aq"]).
在正则表达式和Google搜索中我是新手我到目前为止还没找到解决方案,有人做知道怎么做吗?
Being new at regex and Google search I haven't found so far the solution, does someone know how to do this please ?
布鲁诺
推荐答案
你不要我需要一个正则表达式。修改自 http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html :
You don't need a regular expression for this. Modified from http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html:
function getUrlVars(href)
{
var vars = [], hash;
var hashes = href.slice(href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
然后你可以这样做:
var v = getUrlVars("http://www.google.com/webhp?hl=en#sclient=psy&hl=en&site=webhp&source=hp&q=car&aq");
var q = v.q;
这篇关于在Javascript中从Google搜索中提取关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!