Extracting value from HTML Responce using Regular

2020-02-07 03:10发布

I am getting response from Jmeter like this:

<input type="hidden" id="queueItemId" name="queueItemId" value="3256"/>

I wanted to get value 3256 from this and store it in a variable. Then i can use this variable further use like ${variable}. For this i am using RegularExpressionExtractor in scope of the Sampler.

Please give me the regular expression to extract this value.

8条回答
仙女界的扛把子
2楼-- · 2020-02-07 03:22

Here is the XPath query:-

//input[@type="hidden"][@id="queueItemId"][@name="queueItemId"]@value

查看更多
女痞
3楼-- · 2020-02-07 03:28

Better than using regular expression to extract that value I would suggest using XPath Extraction like this:

//form[@name='MyForm']//input[@name='queueItemId']/@value

Where MyForm is your form name, replace with whatever you have.

查看更多
▲ chillily
4楼-- · 2020-02-07 03:29

Actually the best awnser is from Ibu in the comment:

value=\"(\d+)\" and: value="([^"]+?)" will workfine too

So in jemter it will look like this:

reference name: value

Regex: (\s value=\"(\d+)\")

Regex: (\s value="([^"]+?)")

template : $2$

match no.:1

If you want only the value that have the reference name queueItemId you might want to modify the reg ex to this.

So from jmeter reg ex extractor you got :

reference name: queueItemId

Regex: (name="queueItemId" \s value="([^"]+?)")

Regex: (name="queueItemId" \s value=\"(\d+)\")

template : $2$

match no.:1

You should check the regex with jakarta oro because it's the reg ex engine that jmeter use.

Check out jakarta ORO here : http://jakarta.apache.org/oro/demo.html

ORO is a reg ex tool that behave almost exactly like jmeter.

Most of the time the the standart reg ex tool will work but it has happened to me sometime that the reg ex was fine in my tool but was not working in jmeter.

I later found out the ORO tool and was able to make it work in oro (and jmeter)

Another note: I think jmeter ignore space in your reg ex you have to add /s when you want to compare a space.

查看更多
Bombasti
5楼-- · 2020-02-07 03:32

The most maintainable way in recent version of JMeter is to use CSS/JQuery Extractor:

Using CSS/JQuery

The most performing one is to use new Boundary Extractor:

Boundary Extractor

If you really want to use Regular_Expression_Extractor :

Regex

查看更多
SAY GOODBYE
6楼-- · 2020-02-07 03:34

or try this code regexId = '\d+';

查看更多
家丑人穷心不美
7楼-- · 2020-02-07 03:35
var str = "<a href='/openmrs/module/moca/encounterViewer.form?encounterId=3537'></a>"
var regex = /<a.*?href='(.*?)'/;
var src = regex.exec(str)[1];
var numb = src.split("=")[1];
alert (numb);
查看更多
登录 后发表回答