Jmeter 未使用 reg ex 提取器正确提取值

发布于 2024-09-01 19:40:51 字数 1271 浏览 3 评论 0原文

Jmeter 未使用正则表达式正确提取值。
当我在正则表达式教练中使用以下 html 玩这个正则表达式 (NAME="token" \s value="([^"]+?)") 时,一切正常,但是当添加 reg 时请求的正则表达式提取器即使输出中是相同的 html,也找不到该值

<HTML>
<script type="text/javascript">
    function dostuff(no, applicationID)
    {
        submitAction('APPS_NAME' , 'noSelected=' + no + '&applicationID=' + applicationID);
    }
</script>

<FORM NAME="baseForm" ACTION="" METHOD="POST">
    <input type="hidden" NAME="token" value="fc95985af8aa5143a7b1d4fda6759a74" >

<div id="loader" align="center">
        <div>
            <strong style="color: #003366;">Loading...</strong>
        </div>
        <img src="images/initial-loader.gif" align="top"/>
    </div>

<BODY ONLOAD="dostuff('69489','test');">

</FORM>
</HTML>  

来自正则表达式提取器

Reference Name: token
Regular Expression: (NAME="token" \s value="([^"]+?)")
Template: $1$
Match No.: 1
Default value: wrong-token

上一个代码的 POST 之后的请求正在返回:

POST data:
token=wrong-token

在下一个中 。但是当我检查代理

中的真实请求时,令牌就在那里。

注意:我尝试了不带括号的正则表达式,但也不起作用。


为什么 jmeter 无法使用正则表达式提取器找到我的令牌?

Jmeter is not extracting correctly the value with the regex.
When I play with this regex (NAME="token" \s value="([^"]+?)") in regex coach with the following html everything work fine but when adding the reg with a regex extrator to the request he doesn't found the value even if it's the same html in output.

<HTML>
<script type="text/javascript">
    function dostuff(no, applicationID)
    {
        submitAction('APPS_NAME' , 'noSelected=' + no + '&applicationID=' + applicationID);
    }
</script>

<FORM NAME="baseForm" ACTION="" METHOD="POST">
    <input type="hidden" NAME="token" value="fc95985af8aa5143a7b1d4fda6759a74" >

<div id="loader" align="center">
        <div>
            <strong style="color: #003366;">Loading...</strong>
        </div>
        <img src="images/initial-loader.gif" align="top"/>
    </div>

<BODY ONLOAD="dostuff('69489','test');">

</FORM>
</HTML>  

From the Regular Expression Extractor

Reference Name: token
Regular Expression: (NAME="token" \s value="([^"]+?)")
Template: $1$
Match No.: 1
Default value: wrong-token

The request following my the POST of the previous code is returning:

POST data:
token=wrong-token

in the next request in the tree viewer.

But when I check a the real request in a proxy the token is there.

Note: I tried the regex without the bracket and doesn't worked either.

Do anybody have a idea whats wrong here?
Why jmeter can't find my token with the regex extrator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

池予 2024-09-08 19:40:51

您的正则表达式查找文本 NAME="token",后跟空格,后跟空格、制表符或换行符,后跟空格,后跟文本 value=",后跟一个或多个非引号字符,最后跟另一个 "

如果它在它正在查看的字符串中找不到该内容(并且您的文本示例不匹配),则会失败。

你到底想做什么?看起来您正在使用正则表达式解析 HTML。这不是一个好主意。

Your regex looks for the text NAME="token", followed by a space, followed by a space, tab or newline, followed by a space, followed by the text value=", followed by one or more non-quote characters, followed by another ".

If it doesn't find that in the string it's looking at (and your text sample doesn't match), it fails.

What are you really trying to do? It looks like you're parsing HTML with regex. Not a good idea.

祁梦 2024-09-08 19:40:51

您可以使用 XPath Extractor 而不是正则表达式提取器。

您的 xpath 查询应该返回您想要提取的值。
在这种情况下,它看起来像:

//input[@type="hidden"][@name="token"]/@value

提取的值将存储在 XPath 提取器的“引用名称”字段中指向的 jmeter 变量中(例如,在您的情况下为 ${token} )。

注意:由于这里使用 XPath Extractor 来解析 HTML(不是 XML)响应,因此请确保选中使用 Tidy(宽容解析器) 选项(在 XPath Extractor 的控制面板)。

You can possibly use XPath Extractor instead of Regular Expression Extractor.

Your xpath query should return value you want to extract.
In this case it will look like:

//input[@type="hidden"][@name="token"]/@value

Extracted value will be stored in jmeter variable pointed in 'Reference Name' field of XPath Extractor (e.g. ${token} in your case).

NOTE: Since here XPath Extractor is used to parse HTML (not XML) response ensure that Use Tidy (tolerant parser) option is CHECKED (in XPath Extractor's control panel).

云巢 2024-09-08 19:40:51

您需要按如下方式更新正则表达式格式:

Reference Name: token
Regular Expression: NAME="token"\svalue="(.+)"
Template: $1$
Match No.: 1
Default value: wrong-token

You need to update the regex formats as follows:

Reference Name: token
Regular Expression: NAME="token"\svalue="(.+)"
Template: $1$
Match No.: 1
Default value: wrong-token
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文