github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/md/url_parse.md (about) 1 ### `url_parse()` {#fn-url-parse} 2 3 函数原型:`fn url_parse(key)` 4 5 函数说明:解析字段名称为 key 的 url。 6 7 函数参数 8 9 - `key`: 要解析的 url 的字段名称。 10 11 示例: 12 13 ```python 14 # 待处理数据:{"url": "https://www.baidu.com"} 15 16 # 处理脚本 17 json(_, url) 18 m = url_parse(url) 19 add_key(scheme, m["scheme"]) 20 21 # 处理结果 22 { 23 "url": "https://www.baidu.com", 24 "scheme": "https" 25 } 26 ``` 27 28 上述示例从 url 提取了其 scheme,除此以外,还能从 url 提取出 host, port, path, 以及 url 中携带的参数等信息,如下例子所示: 29 30 ```python 31 # 待处理数据:{"url": "https://www.google.com/search?q=abc&sclient=gws-wiz"} 32 33 # 处理脚本 34 json(_, url) 35 m = url_parse(url) 36 add_key(sclient, m["params"]["sclient"]) # url 中携带的参数被保存在 params 字段下 37 add_key(h, m["host"]) 38 add_key(path, m["path"]) 39 40 # 处理结果 41 { 42 "url": "https://www.google.com/search?q=abc&sclient=gws-wiz", 43 "h": "www.google.com", 44 "path": "/search", 45 "sclient": "gws-wiz" 46 } 47 ```