How to extract value from option tag instead of text

Information related to the use of iMacros for Web Scraping, Data Mining and creating Mashups.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team
Post Reply
ravi_npatty
Posts: 22
Joined: Sat May 07, 2011 6:12 am

How to extract value from option tag instead of text

Post by ravi_npatty » Fri May 20, 2011 5:08 pm

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.
siniy
Posts: 118
Joined: Sat Nov 07, 2009 7:44 pm

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

Post by siniy » Fri May 20, 2011 9:30 pm

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}}
ravi_npatty
Posts: 22
Joined: Sat May 07, 2011 6:12 am

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

Post by ravi_npatty » Sat May 21, 2011 1:39 pm

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.
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

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

Post by Tom, Tech Support » Wed May 25, 2011 8:14 pm

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.
Regards,

Tom, iMacros Support
Post Reply