Number of Options in a Select tag

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Number of Options in a Select tag

by rfashanu2 on Sun Apr 06, 2008 7:59 am

Hello.. I need to find out how I can get the number of options in a Select tag

For example, the following Select tag has 3 options. I would like to be able to get the value 3 using Imacros and some VBScripting if required..

Code: Select all
   <SELECT NAME="name1">
      <OPTION VALUE="value1" SELECTED>Item1
      <OPTION VALUE="value2" >Item2
      <OPTION VALUE="value3" >Item3
   </SELECT>


thanks
rfashanu2
 
Posts: 1
Joined: Sun Apr 06, 2008 7:54 am

Re: Number of Options in a Select tag

by Tech Support on Sun Apr 06, 2008 4:41 pm

Here is how to get the number of entries in a select box:

1. Use a TAG command that tries to select a non-existing entry. Example:
Code: Select all
URL GOTO=http://www.iopus.com/imacros/demo/v6/f1/form.asp     
TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:main CONTENT=2000


2. The returned error message contains the number of entries in the select box:
Selected entry not available:2000 [Box has 3 entries]. Disable this message with SET !ERRORIGNORE YES

This error message is also returned via iimGetLastError, so you can use this value with VBS and any other programming language.
User avatar
Tech Support
 
Posts: 5003
Joined: Tue Sep 20, 2005 12:25 pm

Re: Number of Options in a Select tag

by chivracq on Thu Aug 27, 2015 6:17 pm

I needed the same Functionality in pure .iim as I don't use any .js Scripts (in order to be able to select automatically the last possible Option in a DDLB with a variable Number of Options...) and I came up with the following Solution:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
'SET !EXTRACT_TEST_POPUP NO

URL GOTO=http://www.iopus.com/imacros/demo/v6/f1/form.asp
'TAG POS=1 TYPE=SELECT FORM=ID:TestForm ATTR=NAME:main CONTENT=$French<SP>Fries

TAG POS=1 TYPE=SELECT FORM=ID:TestForm ATTR=NAME:main EXTRACT=TXTALL
'=> Extracted: "--- Please select ---[OPTION]Pizza[OPTION]French Fries[OPTION]Bread & Butter"

'Calculate Nb of Options in DDLB (by using the Length of the Array after a 'split()'):
SET DDLB_Nb_of_Options EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('[OPTION]'); x=y.length; x;")
PROMPT DDLB_Nb_of_Options:<SP>_{{DDLB_Nb_of_Options}}_

'Select Last Option in DDLB:
TAG POS=1 TYPE=SELECT FORM=ID:TestForm ATTR=NAME:main CONTENT=#{{DDLB_Nb_of_Options}}
'=> 'Bread & Butter' gets selected!
(Tested on iMacros for FF v8.8.2, Pale Moon v24.6.2 (=FF31), Win7-x64.)

>>>

EDIT (Tu.2015/10/27):
Adding a few TAGS to be able to find this Thread again as the 'SEARCH FORUM' Functionality doesn't look into 'CODE' Blocks:
JFC_TAG/JFC_TAGS: DDLB, Array, Length, SELECT, Option, Options, EVAL, split
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Number of Options in a Select tag

by chivracq on Thu May 12, 2016 8:38 am

Ah-ah-ah...!! Mini-Explanation for myself (yep, I'm a bit dumb sometimes...!) about the Code in my previous Post as I was just reviewing it to refer to this Thread for some other Thread, I thought for a while there was a mini-Mistake in my use of the Length of the Array as I would expect a -1 to get the correct Number of Items, but...!, Explanation is that it is a DDLB with a first empty Row before selecting any Item in the DDLB...

And I'm not sure my Remark about the Forum Search Engine not being able to search inside ']code[' Blocks is correct...
OK, testing now:
Code: Select all
UniKKeyWWord Ah-ah...!

Yep, doesn't work (using the exact same Spelling, with Capitals included):
No posts were found because the word unikkeywword is not contained in any post.

Code: Select all
unikkeywword Ah-ah...!

Well, doesn't work either (using lowercase for the Search Term and having truncated the previous Quote), but the Msg is different:
No suitable matches were found.

And if I don't truncate the "Keyword" in the first Quote, the Post is found (same Result using Lowercase or with Capitals included) with all Words highlighted...!? :?

It's a bit confusing, but it seems I was right, the Forum Search Engine does NOT look inside ']code[' Blocks, or it looks inside for the Highlighting but only if the Term has already been found in Plain Text or in a Quote within the same Post.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6473
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 7 guests

-->