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.

Moderator: iMacros Moderators

How to extract value from option tag instead of text

by ravi_npatty on Fri May 20, 2011 10:08 am

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.
ravi_npatty
 
Posts: 16
Joined: Fri May 06, 2011 11:12 pm

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

by siniy on Fri May 20, 2011 2: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}}
siniy
 
Posts: 118
Joined: Sat Nov 07, 2009 12:44 pm

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

by ravi_npatty on Sat May 21, 2011 6:39 am

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.
ravi_npatty
 
Posts: 16
Joined: Fri May 06, 2011 11:12 pm

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

by Tom, Tech Support on Wed May 25, 2011 1: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
Tom, Tech Support
 
Posts: 3298
Joined: Mon May 31, 2010 9:59 am


Return to How-To's and Examples for Web Scraping

Who is online

Users browsing this forum: No registered users and 1 guest

-->