添加函数 url.getParameters

This commit is contained in:
吕金泽 2019-09-28 18:30:10 +08:00
parent 5ca08aeac8
commit 24ff424eb9

View File

@ -4,6 +4,8 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import org.spiderflow.annotation.Comment;
import org.spiderflow.annotation.Example;
@ -23,6 +25,20 @@ public class UrlFunctionExecutor implements FunctionExecutor{
return "url";
}
@Comment("获取url后面的参数")
@Example("${url.getParameters('http://www.baidu.com/s?wd=spider-flow')}")
public static Map<String,String> getParameters(String url){
int index = url.indexOf("?");
String param = url.substring(index+1);
String[] params = param.split("&");
Map<String,String> map = new HashMap<String,String>();
for (String item:params) {
String[] kv = item.split("=");
map.put(kv[0],kv[1]);
}
return map;
}
@Comment("url编码")
@Example("${url.encode('http://www.baidu.com/s?wd=spider-flow')}")
public static String encode(String url){