Postman如何从响应(不是JSON或XML)中获取数据?

时间:2019-09-27 03:15:20

标签: html postman

<html>
    <head>
        <meta http-equiv="expires" content="0">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <LINK href="style.css" type=text/css rel=stylesheet>
        <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
        <script type="text/javascript" src="position.js"></script>
        <script type="text/javascript" src="common.js"></script>
        <script type="text/javascript" src="copyright.js"></script>
        <!--[if lt IE 7.]
    <script defer type="text/javascript" src="pngfix.js"></script>
    <LINK href="style2.css" type=text/css rel=stylesheet>
    [endif]-->

    </head>
    <script>
        var session_key='09fcf555eb2814024ee22e47cacfb04e';
    //get user power
    var NOWPATH = get_now_url();
    var user_power="0";
    if ( NOWPATH == "/" )
            NOWPATH = document.location.pathname.substring(1,document.location.pathname.length);

    /* get page url*/
    function goto_home()
    {
        if(user_power == '0') //Admin
            goto_page("quicksetup.asp",0);
        else //User
            goto_page("wan_sub_u.asp",0);
    }
    </script>
    <body></body>
</html>

如上所述,这是一个HTML响应,我想从HTML文本中获取变量“ session_key”的值。但是我不知道如何用邮递员来做。

1 个答案:

答案 0 :(得分:0)

在测试中尝试类似的方法:

var sessionKey = responseBody.match('var session_key=\'([a-zA-Z0-9]+)\'')[1];
postman.setEnvironmentVariable("session_key", sessionKey);

然后在环境变量中查找值并在需要的地方重复使用。