邮递员:如何从html响应中提取值并将其传递给邮递员中的下一个请求 [英] Postman: How to extract value from html response and pass it on to next request in postman

查看:123
本文介绍了邮递员:如何从html响应中提取值并将其传递给邮递员中的下一个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例网址:



我确定您可以使用它从示例中获取所需的值。


Example url: https://abc.xyz.com/m# HTML Response:

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
.
.
</head>
<body class="abc">        
.
.
.
<script>xab.start('{\"first\":\"123xyz\",\"second\":\"abc123\",\"third"..;</script>
</div>
</body>
</html>

In the above mentioned response i want to extract the value of the parameter second '("second\":\"abc123\")' from the response and pass it on to the next request.

It would be simpler if the response is JSON, but in the case this is HTML response.

I was able to do this on JMeter using Regex but having hard time to do it on Postman.

Thanks!

解决方案

You could look at using Cheerio to get the values, it's one of the built in modules within the Postman native application.

You could add something like this example, to extract the value from the HTML.

This is getting the value from the title html tag, of the jsonplaceholder page, then setting it as an environment variable:

const $ = cheerio.load(pm.response.text())

pm.test("it should return a title", () => { 
    pm.expect($('title').text()).to.not.be.empty 
})

pm.environment.set('title', $('title').text())

I'm sure you could use this to get the value you need from your example.

这篇关于邮递员:如何从html响应中提取值并将其传递给邮递员中的下一个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆