Extract keyword from Google search in Javascript

后端 未结 3 941
后悔当初
后悔当初 2020-12-03 15:50

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&si

3条回答
  •  借酒劲吻你
    2020-12-03 16:01

    function getParameterByName(name,url) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(url);
        return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    
    
    alert(getParameterByName('q','https://www.google.com/search?q=buy+a+pc&oq=buy+a+pc&aqs=chrome..69i57j5j0l2j69i61.1674j0&sourceid=chrome&ie=UTF-8#psj=1&q=buy+a+pc'));
    

提交回复
热议问题