0

I need to build a regex for extracting the value present under value field. i.e "f70a8c3d0a6cbe2e235c7fd1dd27d052df7412ea"

HTML RESPONSE BODY : Note: I have pasted just a minor part of the response....but formToken key is unique

<div class="hidden">
    <input name="formToken    type="hidden"
            value="f70a8c3d0a6cbe2e235c7fd1dd27d052df7412ea"    
    />
</div>

I wrote the below regex but it returned nothing:

regex("formToken" type="hidden" value="([^"]*)"/>).find(0).exists, found nothing
Andy Lester
  • 91,102
  • 13
  • 100
  • 152
Sunnx
  • 71
  • 12
  • Did you try `regex("""value="([^"]*)"""")`? I mean, you might need to use triple quotation marks. – Wiktor Stribiżew Apr 07 '15 at 23:08
  • Thanks for replying Stribizhev...but the above reponse was just a part of HTML Body It also has more than 50 Values...example ................ – Sunnx Apr 07 '15 at 23:10
  • [Dont parse (X)html with a regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – Willem Van Onsem Apr 07 '15 at 23:10

4 Answers4

0

Can you try this?

regex("type="hidden".*value="(.*?)[ \t]*"/>).find(0).exists
pogo
  • 1,479
  • 3
  • 18
  • 23
  • Thanks Pogo, but as I said earlier we were having more than 1 match for the above regex and our only unique key is formToken, so I think we need to build on that line. – Sunnx Apr 08 '15 at 21:27
  • It would be easier if you give me your full input and expected output. – pogo Apr 09 '15 at 01:18
0

Instead of a regex, you could use a css selector check which is probably way easier once you have ids or css classes to search for.

Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
0

Thank you all....I was able to get formToken using css

.check(css("input[name='formToken']", "value").saveAs("formTokex"))

Sunnx
  • 71
  • 12
0

Works like this for me:

.exec(http("request_1")
        .get("<<<<YOUR_URL>>>>>")
        .check(css("form[name='signInForm']", "action").saveAs("urlPath"))

and later printing it:

println(session( "urlPath" ).as[String])
Adrian Madaras
  • 347
  • 3
  • 13