简体   繁体   English

在JMeter中,如何捕获正则表达式的多个(不同)值?

[英]In JMeter how can I capture multiple (varying) values of a regular expression?

I need to parse a html page that can contain multiple (unspecified how many) links. 我需要解析一个可以包含多个(未指定数量)链接的html页面。 Here an example (pseudo html): 这是一个示例(伪html):

<a href="../entrygroups/GROUPIDENTIFIER/3">edit</a>
[...]
<a href="../entrygroups/GROUPIDENTIFIER/7">edit</a>
[...]
<a href="../entrygroups/GROUPIDENTIFIER/12">edit</a>
[...]
<a href="../entrygroups/GROUPIDENTIFIER/16">edit</a>

I am basically just interested in the numbers 3 , 7 , 12 , 16 of the url. 我基本上是在数字只是感兴趣371216的url。

Is there a way to put those values into some sort of array and loop over them (in a for each kind of way). 有没有一种方法可以将这些值放入某种数组中并在它们上循环(以每种方式的一种)。

Is this possible and if so, how would I do this? 这可能吗?如果可以,我该怎么做? I looked at the regular expression extractor but it seems that that one can only assign a fixed set of groups to a fixed set of variables. 我看了正则表达式提取器,但似乎只能将一组固定的组分配给一组固定的变量。

Actually RegEx extractor is able to do exactly what you want, if you specify Match No. field with less than 0, eg -1 : 实际上,如果您指定小于0(例如-1)的“匹配号”字段 ,则RegEx提取器可以完全满足您的要求。

在此处输入图片说明

As a result, you will get N variables (using your input as example): 结果,您将获得N个变量(以您的输入为例):

id_1=3
id_2=7
id_3=12
id_4=16

There also will be variable which has a count of matches: 也将有一个具有匹配项计数的变量:

id_matchNr=4
  1. Extract the values using Regular Expression Extractor configured like: 使用配置如下的正则表达式提取器提取值:

    • Reference Name: anything meaningful, ie edit 参考名称:任何有意义的内容,即edit
    • Regular Expression: <a href="../entrygroups/GROUPIDENTIFIER/(.+?)">edit</a> 正则表达式: <a href="../entrygroups/GROUPIDENTIFIER/(.+?)">edit</a>
    • Template: $1 模板: $1
    • Match No: -1 比赛编号: -1

      JMeter正则表达式提取器

  2. Add ForEach Controller configured like: 添加配置如下的ForEach Controller

    • Input variable prefix: edit (or whatever you used as the Regular Expression Extractor Reference Name) 输入变量前缀: edit (或用作正则表达式提取器引用名称的任何名称)
    • Output variable prefix: again anything meaningful, ie current_edit 输出变量前缀:同样有意义的任何东西,即current_edit

      在此处输入图片说明

  3. Put the sampler(s) you need under the ForEach Controller 将所需的采样器放在ForEach控制器下
  4. Refer the "GROUPIDENTIFIER" value as ${current_edit} where required 在需要时,将“ GROUPIDENTIFIER”值引用为${current_edit}

    JMeter正则表达式提取器循环值

See Using Regular Expressions in JMeter guide for another example of looping through all links found in the page with the Regular Expression Extractor and ForEach Controller. 有关使用正则表达式提取器和ForEach控制器在页面中找到的所有链接进行循环的另一示例,请参见JMeter指南中的使用正则表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM