云日志服务 LTS-解析函数:url_parse_qs

时间:2024-11-02 18:44:20

url_parse_qs

解析URL中查询字符串的组成部分。

  • 函数格式
    url_parse_qs(
        url_qs,
        keep_blank_values=false,
        strict_parsing=false,
        encoding="utf-8",
        errors="replace",
        ignore_multi_fields=true,
    )
  • 参数说明

    参数名称

    数据类型

    是否必填

    说明

    url_qs

    String

    待解析的URL查询字符串。

    keep_blank_values

    Boolean

    是否返回值为空的参数。

    • false(默认值):不返回。
    • true:返回,且将空值处理为空字符串。

    strict_parsing

    Boolean

    是否处理解析错误。

    • true:解析报错会引发ValueError异常。
    • false(默认值):忽略错误。

    encoding

    String

    指定编码方式,将含有百分号(%)的转义字符解析为Unicode字符,默认为utf-8。支持ASCII。

    errors

    String

    按照编码方式无法识别字符时的处理方案。取值包括:

    • ignore:直接忽略。
    • strict:直接报错,丢弃此条日志数据。
    • replace(默认值):使用半角问号(?)替换无法识别部分。
    • xmlcharrefreplace:使用对应XML字符替换无法识别部分。

    ignore_multi_fields

    Num

    指定单个返回参数的值的个数。

    • true(默认值):每个参数只返回第一个值, 类型为String。
    • false:每个参数都返回所有值,类型为List。
  • 返回结果

    返回解析后的JSON数据,具体参数说明如下表所示。

    字段

    说明

    logType

    日志类型

    uid

    日志的唯一标识

    time

    日志的时间

    msg

    日志中的信息

  • 函数示例
    1. 示例1:设置keep_blank_values为true,返回结果中包含值为空的参数。
      • 测试数据
        {
          "content":"logType=net_wheel_log&uid=62452****&vid=6.1.0_gf_pc&asb=1206427&git=&time=22-11-3+%e4%b8%8a11%e6%97%b649%e5%88%8633%e7%a7%92&operatingSystem=Windows+10++(10.0.0)+64bit&deviceModel=System+Product+Name+(System+manufacturer)&graphicsDeviceName=NVIDIA+GeForce+GTX+1650&graphicsDeviceType=Direct3D11&graphicsDeviceVendor=NVIDIA&graphicsDeviceVersion=Direct3D+11.0+%5blevel+11.1%5d&graphicsMemorySize=3962&systemMemorySize=8127&processorCount=6&processorFrequency=3000&processorType=Intel(R)+Core(TM)+i5-9500F+CPU+%40+3.00GHz&deviceID=96da5902a042a5f84118995f88373f73650e76be166589726****&guessUID=62452****&networkReachability=wifi&msg=GetAuthkeyRsp"
        }
      • 加工规则
        e_set("url",url_parse_qs(v("content"), keep_blank_values=true))
      • 加工结果
        content:logType=net_wheel_log&uid=62452****&vid=6.1.0_gf_pc&asb=1206427&git=&time=22-11-3+%e4%b8%8a11%e6%97%b649%e5%88%8633%e7%a7%92&operatingSystem=Windows+10++(10.0.0)+64bit&deviceModel=System+Product+Name+(System+manufacturer)&graphicsDeviceName=NVIDIA+GeForce+GTX+1650&graphicsDeviceType=Direct3D11&graphicsDeviceVendor=NVIDIA&graphicsDeviceVersion=Direct3D+11.0+%5blevel+11.1%5d&graphicsMemorySize=3962&systemMemorySize=8127&processorCount=6&processorFrequency=3000&processorType=Intel(R)+Core(TM)+i5-9500F+CPU+%40+3.00GHz&deviceID=96da5902a042a5f84118995f88373f73650e76be166589726****&guessUID=62452****&networkReachability=wifi&msg=GetAuthkeyRsp
         url:{
                "logType": "net_wheel_log",
                "uid": "62452****", 
               "vid": "6.1.0_gf_pc", 
               "asb": "1206427", 
               "git": "", 
               "time": "22-11-3 上11时49分33秒",
                "operatingSystem": "Windows 10  (10.0.0) 64bit",
                "deviceModel": "System Product Name (System manufacturer)",
                "graphicsDeviceName": "NVIDIA GeForce GTX 1650",
                "graphicsDeviceType": "Direct3D11",
                "graphicsDeviceVendor": "NVIDIA",
                "graphicsDeviceVersion": "Direct3D 11.0 [level 11.1]", 
               "graphicsMemorySize": "3962",
                "systemMemorySize": "8127", 
               "processorCount": "6",
                "processorFrequency": "3000",
                "processorType": "Intel(R) Core(TM) i5-9500F CPU @ 3.00GHz", 
               "deviceID": "96da5902a042a5f84118995f88373f73650e76be166589726****", 
               "guessUID": "62452****",
               "networkReachability": "wifi", 
               "msg": "GetAuthkeyRsp",
            }
    2. 示例2:设置keep_blank_values为默认值(false),返回结果无值为空的参数。
      • 测试数据
        {
           "content":"logType=net_wheel_log&uid=62452****&vid=6.1.0_gf_pc&asb=1206427&git=&time=22-11-3+%e4%b8%8a11%e6%97%b649%e5%88%8633%e7%a7%92&operatingSystem=Windows+10++(10.0.0)+64bit&deviceModel=System+Product+Name+(System+manufacturer)&graphicsDeviceName=NVIDIA+GeForce+GTX+1650&graphicsDeviceType=Direct3D11&graphicsDeviceVendor=NVIDIA&graphicsDeviceVersion=Direct3D+11.0+%5blevel+11.1%5d&graphicsMemorySize=3962&systemMemorySize=8127&processorCount=6&processorFrequency=3000&processorType=Intel(R)+Core(TM)+i5-9500F+CPU+%40+3.00GHz&deviceID=96da5902a042a5f84118995f88373f73650e76be166589726****&guessUID=62452****&networkReachability=wifi&msg=GetAuthkeyRsp"
        }
      • 加工规则
        e_set("url",url_parse_qs(v("content")))
      • 加工结果
        content:logType=net_wheel_log&uid=62452****&vid=6.1.0_gf_pc&asb=1206427&git=&time=22-11-3+%e4%b8%8a11%e6%97%b649%e5%88%8633%e7%a7%92&operatingSystem=Windows+10++(10.0.0)+64bit&deviceModel=System+Product+Name+(System+manufacturer)&graphicsDeviceName=NVIDIA+GeForce+GTX+1650&graphicsDeviceType=Direct3D11&graphicsDeviceVendor=NVIDIA&graphicsDeviceVersion=Direct3D+11.0+%5blevel+11.1%5d&graphicsMemorySize=3962&systemMemorySize=8127&processorCount=6&processorFrequency=3000&processorType=Intel(R)+Core(TM)+i5-9500F+CPU+%40+3.00GHz&deviceID=96da5902a042a5f84118995f88373f73650e76be166589726****&guessUID=62452****&networkReachability=wifi&msg=GetAuthkeyRsp
         url:{
                "logType": "net_wheel_log",
                "uid": "62452****",
                "vid": "6.1.0_gf_pc",
                "asb": "1206427", 
               "time": "22-11-3 上11时49分33秒",
                "operatingSystem": "Windows 10  (10.0.0) 64bit",
                "deviceModel": "System Product Name (System manufacturer)",
                "graphicsDeviceName": "NVIDIA GeForce GTX 1650",
                "graphicsDeviceType": "Direct3D11",
                "graphicsDeviceVendor": "NVIDIA", 
               "graphicsDeviceVersion": "Direct3D 11.0 [level 11.1]", 
               "graphicsMemorySize": "3962",
                "systemMemorySize": "8127", 
               "processorCount": "6", 
               "processorFrequency": "3000",
                "processorType": "Intel(R) Core(TM) i5-9500F CPU @ 3.00GHz",
                "deviceID": "96da5902a042a5f84118995f88373f73650e76be166589726****",
                "guessUID": "62452****",
                "networkReachability": "wifi",
                "msg": "GetAuthkeyRsp",
            }
    3. 示例3:设置ignore_multi_fields为默认值(true),每个参数只返回第一个值。
      • 测试数据
        {
           "content":"logType=net_log&uid=62452****&x=1&x=2&x=3&asb=123&asb=456"
        }
      • 加工规则
        e_set("url",url_parse_qs(v("content")))
      • 加工结果
        content:logType=net_log&uid=62452****&x=1&x=2&x=3&asb=123&asb=456
        url:{
            "logType": "net_log", 
           "uid": "62452****",
            "x": "1"
            "asb": "123"
        }
    4. 示例4:设置ignore_multi_fields为false,每个参数返回所有值。
      • 测试数据
        {
          "content":"logType=net_log&uid=62452****&x=1&x=2&x=3&asb=123&asb=456"
        }
      • 加工规则
        e_set("url",url_parse_qs(v("content"),ignore_multi_fields=false))
      • 加工结果
        content:logType=net_log&uid=62452****&x=1&x=2&x=3&asb=123&asb=456
        url:{
            "logType": ["net_log"],
              "uid": ["62452****"],
              "x": ["1", "2", "3"],
              "asb": ["123", "456"],
        }
support.huaweicloud.com/usermanual-lts/lts_07_0146.html