You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Silvester Pozarnik <si...@ko.no> on 2009/09/22 12:20:39 UTC

help needed - Regular Expressions

Hi all,

I am stuck with the following problem. Given the response with data 
containing:

<select name="A" id="selectA">
  <option value="">none</option>
  <option value="01">first</option>
  <option value="02">second</option>
</select>

<select name="B" id="selectB">
  <option value="">none</option>
  <option value="01">first</option>
  <option value="02">second</option>
</select>

what is a way of getting JMeter to loop thorough values of options for 
the <select> "block A" _only_? I need values "", "01" and "02" only to 
loop thorough.

I can get a Regular Expression extractor to fetch a complete <select> 
block by using:

    (?s)<select\s+name="A".*?>(.+?)</select>

I can get _all_ six <option>s by using:

    <option\s+value\="([^"]+)">

Just to make clear the reg.ex.:

<select\s+name="A"\s+id="selectA">(\s*<option\s+value="([^"]+)">[^<]+<\/option\>)+\s+</select>

does not work. This is a universal problem where looping thorough same 
element types but having the parent with unique ID as when using several 
lists, tables etc. on the same html page

Silvester


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: help needed - Regular Expressions

Posted by Deepak Shetty <sh...@gmail.com>.
XPATH extractor with HTML works with the tidy option checked.
regards
deepak


On Tue, Sep 22, 2009 at 4:16 AM, Barnabas Davoti <da...@gmail.com>wrote:

> Noel O'Brien wrote:
>
>> Why not use the following XPath extractor instead:
>> //select[@name="A"]/option/@value
>>
>
> That's a good news... I was wondering why should we use regular expressions
> for extracting data from an XML document... of course as far as it's XML
> (XHTML), but anyway in this case it's proper XML.
>
> I guess xpath is not an option if the page is html (so not XML but SGML) or
> the document is not well-formed XML.
>
> Regards,
>
>  Barna
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: help needed - Regular Expressions

Posted by sebb <se...@gmail.com>.
On 01/10/2009, Silvester Pozarnik <si...@ko.no> wrote:
> sebb skrev:
>
> > On 22/09/2009, Barnabas Davoti <da...@gmail.com> wrote:
> >
> >
> > > Noel O'Brien wrote:
> > >
> > >
> > >
> > > > Why not use the following XPath extractor instead:
> > > > //select[@name="A"]/option/@value
> > > >
> > > >
> > > >
> > >  That's a good news... I was wondering why should we use regular
> expressions
> > > for extracting data from an XML document... of course as far as it's XML
> > > (XHTML), but anyway in this case it's proper XML.
> > >
> > >  I guess xpath is not an option if the page is html (so not XML but
> SGML) or
> > > the document is not well-formed XML.
> > >
> > >
> >
> > I don't think it's possible to do it with a single RE.
> >
> > However, one can use the RE extractor to extract the specific set of
> > options into a variable, and then use the __regexFunction() to split
> > the variable. But XPath is simpler.
> >
> > It might be useful to enhance the RE extractor to operate on a subset
> > of the body...
> >
> >
> >
>  Jepp, XPath may work, but I am still interested in a template for looping
> thought the results of __regexFunction() as a second level looping because
> HTML codes are often not balanced, especially in tables.

Which is where Tidy comes in handy.

>  BR
>  Silvester Pozarnik
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: help needed - Regular Expressions

Posted by Silvester Pozarnik <si...@ko.no>.
sebb skrev:
> On 22/09/2009, Barnabas Davoti <da...@gmail.com> wrote:
>   
>> Noel O'Brien wrote:
>>
>>     
>>> Why not use the following XPath extractor instead:
>>> //select[@name="A"]/option/@value
>>>
>>>       
>>  That's a good news... I was wondering why should we use regular expressions
>> for extracting data from an XML document... of course as far as it's XML
>> (XHTML), but anyway in this case it's proper XML.
>>
>>  I guess xpath is not an option if the page is html (so not XML but SGML) or
>> the document is not well-formed XML.
>>     
>
> I don't think it's possible to do it with a single RE.
>
> However, one can use the RE extractor to extract the specific set of
> options into a variable, and then use the __regexFunction() to split
> the variable. But XPath is simpler.
>
> It might be useful to enhance the RE extractor to operate on a subset
> of the body...
>
>   
Jepp, XPath may work, but I am still interested in a template for 
looping thought the results of __regexFunction() as a second level 
looping because HTML codes are often not balanced, especially in tables.

BR
Silvester Pozarnik


Re: help needed - Regular Expressions

Posted by sebb <se...@gmail.com>.
On 22/09/2009, Barnabas Davoti <da...@gmail.com> wrote:
> Noel O'Brien wrote:
>
> > Why not use the following XPath extractor instead:
> > //select[@name="A"]/option/@value
> >
>
>  That's a good news... I was wondering why should we use regular expressions
> for extracting data from an XML document... of course as far as it's XML
> (XHTML), but anyway in this case it's proper XML.
>
>  I guess xpath is not an option if the page is html (so not XML but SGML) or
> the document is not well-formed XML.

I don't think it's possible to do it with a single RE.

However, one can use the RE extractor to extract the specific set of
options into a variable, and then use the __regexFunction() to split
the variable. But XPath is simpler.

It might be useful to enhance the RE extractor to operate on a subset
of the body...

>  Regards,
>
>   Barna
>
>
> ---------------------------------------------------------------------
>
>  To unsubscribe, e-mail:
> jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail:
> jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: help needed - Regular Expressions

Posted by Barnabas Davoti <da...@gmail.com>.
Noel O'Brien wrote:
> Why not use the following XPath extractor instead:
> //select[@name="A"]/option/@value

That's a good news... I was wondering why should we use regular 
expressions for extracting data from an XML document... of course as far 
as it's XML (XHTML), but anyway in this case it's proper XML.

I guess xpath is not an option if the page is html (so not XML but SGML) 
or the document is not well-formed XML.

Regards,

   Barna


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: help needed - Regular Expressions

Posted by Noel O'Brien <no...@newbay.com>.
Why not use the following XPath extractor instead: 

//select[@name="A"]/option/@value 

Regards, 
Noel 

----- "Silvester Pozarnik" <si...@ko.no> wrote: 
> Hi all, 
> 
> I am stuck with the following problem. Given the response with data 
> containing: 
> 
> <select name="A" id="selectA"> 
> <option value="">none</option> 
> <option value="01">first</option> 
> <option value="02">second</option> 
> </select> 
> 
> <select name="B" id="selectB"> 
> <option value="">none</option> 
> <option value="01">first</option> 
> <option value="02">second</option> 
> </select> 
> 
> what is a way of getting JMeter to loop thorough values of options for 
> the <select> "block A" _only_? I need values "", "01" and "02" only to 
> loop thorough. 
> 
> I can get a Regular Expression extractor to fetch a complete <select> 
> block by using: 
> 
> (?s)<select\s+name="A".*?>(.+?)</select> 
> 
> I can get _all_ six <option>s by using: 
> 
> <option\s+value\="([^"]+)"> 
> 
> Just to make clear the reg.ex.: 
> 
> <select\s+name="A"\s+id="selectA">(\s*<option\s+value="([^"]+)">[^<]+<\/option\>)+\s+</select> 
> 
> does not work. This is a universal problem where looping thorough same 
> element types but having the parent with unique ID as when using several 
> lists, tables etc. on the same html page 
> 
> Silvester 
> 
> 
> --------------------------------------------------------------------- 
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org 
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org 
> 
>