邮递员:如何从 html 响应中提取值并将其传递给邮递员中的下一个请求

编程入门 行业动态 更新时间:2024-10-27 06:28:17
本文介绍了邮递员:如何从 html 响应中提取值并将其传递给邮递员中的下一个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

示例网址:

我相信您可以使用它从您的示例中获得所需的价值.

Example url: abc.xyz/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 响应中提取值并将其传递给邮递员中的下一个请求

本文发布于:2023-10-29 08:33:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮递员   并将其   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!