如何从postman中的http response > body> script tag > window.location.href中提取token和其他文件?

7dl7o3gd  于 2023-08-05  发布在  Postman
关注(0)|答案(1)|浏览(163)

我想从postman中提取token、cookieToken、user_id、refresh_token和expire_date。
html响应:

sampleWebSite Accounts
        
                    var module_hash_id_storage = 1;
                    var module_no_replace_update_command_status = 1;
                    var module_mc_router = 1;
                    var module_vod = 1;
                

            <meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="shortcut icon"
      href="https://demo-sso.sampleWebSite.com/static/files/5f198988.ico#sampleWebSite/supernova-admin/assets/local/single/favicon.ico" type="image/icon">

        <link rel="stylesheet"
          href="/static/merged/d6688deb.css" />
        <link rel="stylesheet"
          href="/static/merged/4e311918.css" />
        <link rel="stylesheet"
          href="/static/merged/3c12da9d.css" />

        <script>
                    var supernova_mode = "demo";
                    var supernova_tracker_url = "";
                </script>
    
        <script src="/static/merged/d993d712.js" ></script>



<div id="sampleWebSite-logo">
    <img src="https://demo-sso.sampleWebSite.com/static/files/8dea606c.svg#sampleWebSite/supernova-sampleWebSite-accounts/assets/img/sampleWebSite.svg">
</div>
    <form method="post" class="uk-form-stacked" action="">
    <div id="login-form">
        <header>
            <i class="icon" uk-icon="icon: basic-lock-open; ratio: 2.5"></i>
            <span class="title">Redirecting...</span><br>
        </header>
    </div>
</form>
<div id="redirecting">
                <div class="panel circle-effect">
            <a>
                <i uk-icon="icon: dk-account; ratio: 1.9"></i>
                <div class="title">Accounts</div>
            </a>
        </div>
        </div>

<script>setTimeout(function () { window.location.href ="https://demo-sso.sampleWebSite.com/login/accounts/callback?token=b98094011a701137cb3c1e835099e26f8107184b64a937c4c0696&cookieToken=b98094011a701137cb3c1e835099e81f8107184b68a937c4c0696%3A1688811460%3Ab3d67af5b3a409b27736e42dafe86776&user_id=Y6ArRDAyUG12R2tDRG9xMlcxR2hXdz09&refresh_token=e11dba8929e77a70fd664e2264271a5032ec30fb64a937c4c069c&expire_date=1691993460"; } ,20)</script>

字符串
我想在一些变量中有一个关于这些(token,cookieToken,user_id,refresh_token和expire_date)的值。

ee7vknir

ee7vknir1#

我找到了解决方案:

const $ = cheerio.load(pm.response.text());
console.log($('body >  script ').text());
const urls = $('body >  script').text().match(/(http|https|ftp):\/\/(\S*)/ig);
var url=urls[0].replace('";','').replace("';'",'')
console.log(urls);
if(urls&&urls.length>0){
var queryDict = {};
var queryString=url.split("?");
if(queryString.length==2){
queryString[1].split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]});
}

字符串

相关问题