我想获取当前页面的URL(使用page:env("caller"))并提取其中的一部分.
例如,我想采取
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=cats
Run Code Online (Sandbox Code Playgroud)
并指派
cats
Run Code Online (Sandbox Code Playgroud)
变量.
我如何用KRL做到这一点?
我试过了
url = page:env("caller");
query = url.replace("http://www\.google\.com/search\?sourceid=chrome&ie=UTF-8&q=", "");
Run Code Online (Sandbox Code Playgroud)
但它只是将整个页面:env("调用者")分配给变量查询(例如http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=cats).
编辑:jQuery解决方案也很有可能.
编辑2:@JAM -
您发布的select语句似乎不起作用.我在http://www.google.com/search?q=cats上对其进行了测试,但它没有触发.不确定网址是否与网页浏览不匹配(看起来它应该与我匹配).
我把它放入的应用程序:
ruleset a835x36 {
meta {
name "regex testing2"
description <<
>>
author ""
logging on
}
rule get_query {
select when pageview "http://www.google.com/search.*(?:&|?)q=(\w+)(?:&|$)" setting(query)
notify("Query",query) with sticky = true;
}
}
Run Code Online (Sandbox Code Playgroud)
另外,我在寻找一个更强大的方式来获得在查询,因为谷歌有很多方法可以在搜索结果页面上的土地使用URL不会像http://www.google.com/search?q =猫.例如,去谷歌和搜索猫只是给了http://www.google.com/webhp?hl=en#sclient=psy&hl=en&site=webhp&source=hp&q=cats&aq=f&aqi=&aql=&oq=&gs_rfai=&pbx= 1&fp = 8ac6b4cea9b27ecb作为结果的URL.我想我可以用正则表达式解析任何东西,但是...