Selecting items from dropdown list and extracting data.

Discussions and Tech Support specific to the iMacros for Chrome extension.
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

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
vinodh87
Posts: 4
Joined: Wed Aug 17, 2016 4:00 am

Selecting items from dropdown list and extracting data.

Post by vinodh87 » Wed Aug 17, 2016 4:37 am

First thing first.

I'm a newbie to iMacro and but have found iMacro very interesting. And would request you all to help me with iMacro.

1. What version of iMacros are you using?
VERSION BUILD=844 RECORDER=CR

2. What operating system are you using? (please also specify language)
Windows 8.1,English

3. Which browser(s) are you using? (include version numbers)
Chrome Version 52.0.2743.116 m

4. What website are you using the macro ?
https://www.rio2016.com/en
-> Select "Athletes<SP>&<SP>Teams" in the side panel.
-> Select a country and Hit Enter.
-> From the list of the athletes select one by one and in the next page extract the Athletes information.
-> Similarly do this for all country and all athletes listed.

Here is the code that I use and the Questions are below the Code.

Code: Select all

VERSION BUILD=844 RECORDER=CR
URL GOTO=https://www.rio2016.com/en
TAG POS=1 TYPE=SPAN ATTR=TXT:Athletes<SP>&<SP>Teams
'TAG POS=1 TYPE=SPAN ATTR=TXT:All<SP>countries
TAG POS=1 TYPE=SPAN ATTR=TXT:Albania
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\Vinodh\Documents\iMacros\Macros FILE=RUn
 
TAG POS=1 TYPE=DIV ATTR=class:sidebar-menu__selector-nav<SP>sidebar-menu--advanced-country
'TAG POS=1 TYPE=UL ATTR=class:sidebar-menu__selector-inside<SP>ps-container<SP>ps-theme-default* EXTRACT=TXT
TAG POS=42 TYPE=LI ATTR=CLASS:sidebar-menu__selector-inside-item EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\Vinodh\Documents\iMacros\Macros FILE=RUn
 
TAG POS=3 TYPE=BUTTON FORM=ACTION:/en/search-athletes ATTR=TXT:Search
TAG POS=1 TYPE=BUTTON ATTR=ID:search-load-more
 
TAG POS=1 TYPE=A ATTR=TXT:CALJA<SP>Briken
 
TAG POS=1 TYPE=TD ATTR=TXT:*
'TAG POS={{!LOOP}} TYPE=TD ATTR=class:about__col<SP>about__col--data EXTRACT=TXT
TAG POS=1 TYPE=TD ATTR=class:about__col<SP>about__col--data EXTRACT=TXT
TAG POS=2 TYPE=TD ATTR=class:about__col<SP>about__col--data EXTRACT=TXT
TAG POS=3 TYPE=TD ATTR=class:about__col<SP>about__col--data EXTRACT=TXT
TAG POS=4 TYPE=TD ATTR=class:about__col<SP>about__col--data EXTRACT=TXT
 
' Display the value within vertical bars to emphasize the spaces
'PROMPT |{{!EXTRACT}}|
 
SET trimmedValue EVAL("\"{{!EXTRACT}}\".replace(/^\\s*|\\s*$/g, \"\");")
PROMPT "|{{trimmedValue}}| - not anymore!"
 
SET !EXTRACT {{trimmedValue}}
 
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\Vinodh\Documents\iMacros\Macros FILE=RUn
BACK
Questions:

1. How to loop Selecting one Country at a time and hitting the search Button ?
2. Is looping possible in iMacro for Chrome extension.
3. When I extract the Hight an Weight text from the athletes page, it consists of a lot of Leading and Trailing spaces, how do i remove them ? so that saving in the excel sheel it would be easy for me.
4. Is VBA programming make it better and easier to do the task I have given here ?
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Selecting items from dropdown list and extracting data.

Post by iimfun » Thu Aug 18, 2016 10:07 am

Hi,

I couldn't make 'iMacros for Chrome' loop over the countries on this site. It seems to me that there's some sort of a bug in loop mode because my macro works flawlessly in usual mode for any country (from 1 to 208).

My conclusion is the following: for your task it's better to apply the free extension 'iMacros for Firefox' & JavaScript Scripting interface.
vinodh87
Posts: 4
Joined: Wed Aug 17, 2016 4:00 am

Re: Selecting items from dropdown list and extracting data.

Post by vinodh87 » Thu Aug 18, 2016 10:47 am

Thanks iimfun for the reply.
iimfun wrote:Hi,

I couldn't make 'iMacros for Chrome' loop over the countries on this site. It seems to me that there's some sort of a bug in loop mode because my macro works flawlessly in usual mode for any country (from 1 to 208).

My conclusion is the following: for your task it's better to apply the free extension 'iMacros for Firefox' & JavaScript Scripting interface.
1. when you say "usual mode for any country (from 1 to 208)" , does that mean selecting one country at a time without looping ?

2. Thanks for the advise about 'iMacros for Firefox'.

But beyond this, would it be possible to use VBA's to achieve what I'm trying to do ? I do not have much idea about java scripting and I was thinking if i need to install firefox to have this sorted.
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Selecting items from dropdown list and extracting data.

Post by iimfun » Thu Aug 18, 2016 1:16 pm

At last I get that worked. Below is a sample code which loops over the countries. Try to play it on https://www.rio2016.com/en in loop mode with the 'Max:' value equal to 208 or less.

Code: Select all

TAG POS=1 TYPE=SPAN ATTR=TXT:Athletes<SP>&<SP>Teams
SET !EXTRACT_TEST_POPUP NO
TAG SELECTOR=".sidebar-menu--advanced-country ul.ps-theme-default li:nth-child({{!LOOP}})" EXTRACT=TXT
SET C EVAL("'{{!EXTRACT}}'.split('[EXTRACT]').pop();")
TAG POS=1 TYPE=SPAN ATTR=TXT:{{C}}
TAG POS=3 TYPE=BUTTON FORM=ACTION:/en/search-athletes ATTR=TXT:Search
WAIT SECONDS=3
BACK
(BTW, it is the '!EXTRACT' variable that works differently from its Firefox analogue! A bug, maybe?)

I can't give any advices about VBA in this case (because don't know its functionality), but I'm pretty sure that just able to solve this task in 'iMacros for Firefox'.
vinodh87
Posts: 4
Joined: Wed Aug 17, 2016 4:00 am

Re: Selecting items from dropdown list and extracting data.

Post by vinodh87 » Fri Aug 19, 2016 11:36 am

Thanks for the code and explaining it.
Only now i understood that the !LOOP variable takes its value from the "Play Loop" mode.

Not sure why the below code had to be placed.

Code: Select all

SET C EVAL("'{{!EXTRACT}}'.split('[EXTRACT]').pop();")
I ran the macro with the above code once and once by commenting it. Saved the extract as .CSV. It all worked fine and there was no difference between the two.

Also could you please let me know the ideal way on to keep selecting each of the athletes information and extract the age, Height and Weight information from the next screen ?
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Selecting items from dropdown list and extracting data.

Post by iimfun » Fri Aug 19, 2016 2:50 pm

Play the following macro on the page with some country ( e.g. https://www.rio2016.com/en/search-athle ... c=Slovenia ) in usual mode

Code: Select all

SET startLoop 1
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=SPAN ATTR=CLASS:"search__total-results txt-uppercase" EXTRACT=TXT
SET maxLoop EVAL("('{{maxLoop}}' == '__undefined__') ? parseInt('{{!EXTRACT}}') : {{maxLoop}};")
SAVEAS TYPE=EXTRACT FOLDER=* FILE=garbage
SET !LOOP EVAL(1-{{maxLoop}}+{{startLoop}})
SET normLoop EVAL({{!LOOP}}+{{maxLoop}}-1)

TAG POS={{normLoop}} TYPE=A ATTR=CLASS:news-page-list__url EXTRACT=TXT
TAB OPEN
TAB T=2
URL GOTO={{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=garbage
TAG POS=1 TYPE=TD ATTR=TXT:Date<SP>of<SP>birth
TAG POS=R1 TYPE=TD ATTR=* EXTRACT=TXT
TAG POS=1 TYPE=TD ATTR=TXT:Height<SP>and<SP>weight
TAG POS=R1 TYPE=TD ATTR=* EXTRACT=TXT
'PROMPT {{!EXTRACT}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=notgarbage
TAB CLOSE
TAB T=1

SET posButMore EVAL("({{normLoop}} % 5 == 0) ? '1' : '';")
SET !ERRORIGNORE YES
TAG POS={{posButMore}} TYPE=BUTTON ATTR=ID:search-load-more
SET !ERRORIGNORE NO
This macro creates two csv files 'garbage' and 'notgarbage'. The latter is more interesting.
vinodh87
Posts: 4
Joined: Wed Aug 17, 2016 4:00 am

Re: Selecting items from dropdown list and extracting data.

Post by vinodh87 » Wed Aug 24, 2016 4:50 am

Thanks iimfun. was down sick, sorry for the late reply.
I'm trying to put all these in one macro and try to run it.
Post Reply