Page 1 of 1

How to extract value from option tag instead of text

Posted: Fri May 20, 2011 5:08 pm
by ravi_npatty
Dear iOpus,

Example html code:

<select name="fruits">
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value=3>Mango</option>
</select>

I can extract the text of selected item in combobox (option tag)
TAG POS=1 TYPE=SELECT FORM=* ATTR=NAME:fruits EXTRACT=TXT
But I want to extract the value of the selected item. I could not find how to do this.

Please help me.

Re: How to extract selected value instead of text from optio

Posted: Fri May 20, 2011 9:30 pm
by siniy
It works for your example. With real website you might need to tweak the regexp. You should learn regular expressions if you don't know them yet.

Code: Select all

'In case this is in loop
SET !EXTRACT NULL
TAG POS=1 TYPE=SELECT FORM=* ATTR=NAME:fruits EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
'Regexp searches for value by previously extracted text
SEARCH SOURCE=REGEXP:"<option value=\"([^\"])\">{{!VAR1}}" EXTRACT="$1"
PROMPT {{!EXTRACT}}

Re: How to extract selected value instead of text from optio

Posted: Sat May 21, 2011 1:39 pm
by ravi_npatty
Thanks siniy.

This did the trick. Thanks a lot. But direct option to extract the value like (TAG POS=1 TYPE=SELECT FORM=* ATTR=NAME:select_name EXTRACT=VALUE) would have been better.

Re: How to extract value from option tag instead of text

Posted: Wed May 25, 2011 8:14 pm
by Tom, Tech Support
Very clever siniy! Thanks for posting your solution!

I have moved this thread to our "How-To's and Examples for Web Scraping" forum and linked it from the Wiki.