Extracting attributes values dynamically imacros

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
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
deepesh
Posts: 3
Joined: Sat Jul 01, 2017 6:44 am

Extracting attributes values dynamically imacros

Post by deepesh » Sat Jul 29, 2017 4:36 am

This is the html text

Code: Select all

  <select name="ctl00$ContentPlaceHolder1$ddltype" id="ctl00_ContentPlaceHolder1_ddltype" class="page-heading" style="background-color: rgb(255, 244, 244); width: 125px; outline: 1px solid blue;">
    			<option value="0">Select Bricks</option>
    			<option value="brk_A_price">A</option>
    			<option value="brk_B_price">B</option>
    			<option value="brk_oth_price">Others</option>
    
    		</select>
    .
    .
    .
    .
    <select name="ctl00$ContentPlaceHolder1$ddlReportOn" id="ctl00_ContentPlaceHolder1_ddlReportOn" class="page-heading" style="background-color:#FFF4F4;width:135px;">
    			<option value="0">Select Report For</option>
    			<option value="1">Comparison</option>
    			<option value="2">Variation</option>
    
    		</select>
So from above html I want to extract option Values i.e brk_A_price,brk_B_price,brk_oth_price from first select tag and 1, 2 from second select tag.

Code: Select all

 'code to get brk_A_price,brk_B_price,brk_oth_price
    TAG POS=1 TYPE=SELECT ATTR=id:ctl00_ContentPlaceHolder1_ddltype&&TXT:* EXTRACT=HTM
    TAG POS R1 TYPE=option ATTR=value&&TXT
    
    'code to get 1, 2
    TAG POS=1 TYPE=SELECT ATTR=id:ctl00_ContentPlaceHolder1_ddlReportOn&&TXT:* EXTRACT=HTM
    TAG POS R1 TYPE=option ATTR=value&&TXT
However, for every dropdown I would want to change just the **id** attribute, but for the code I tried it is just able to extract the text and not values from `<option..>` tag.

> p.s: http://briks.gov.in/Report/Rept_Building_Brik.aspx is the site from where I'm extracting data

Any suggestion on what changes should be made.
Any help would be much appreciated.
Thanks
chivracq
Posts: 8535
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Extracting attributes values dynamically imacros

Post by chivracq » Fri Aug 04, 2017 6:33 am

deepesh wrote:This is the html text

Code: Select all

  <select name="ctl00$ContentPlaceHolder1$ddltype" id="ctl00_ContentPlaceHolder1_ddltype" class="page-heading" style="background-color: rgb(255, 244, 244); width: 125px; outline: 1px solid blue;">
    			<option value="0">Select Bricks</option>
    			<option value="brk_A_price">A</option>
    			<option value="brk_B_price">B</option>
    			<option value="brk_oth_price">Others</option>
    
    		</select>
    .
    .
    .
    .
    <select name="ctl00$ContentPlaceHolder1$ddlReportOn" id="ctl00_ContentPlaceHolder1_ddlReportOn" class="page-heading" style="background-color:#FFF4F4;width:135px;">
    			<option value="0">Select Report For</option>
    			<option value="1">Comparison</option>
    			<option value="2">Variation</option>
    
    		</select>
So from above html I want to extract option Values i.e brk_A_price,brk_B_price,brk_oth_price from first select tag and 1, 2 from second select tag.

Code: Select all

 'code to get brk_A_price,brk_B_price,brk_oth_price
    TAG POS=1 TYPE=SELECT ATTR=id:ctl00_ContentPlaceHolder1_ddltype&&TXT:* EXTRACT=HTM
    TAG POS R1 TYPE=option ATTR=value&&TXT
    
    'code to get 1, 2
    TAG POS=1 TYPE=SELECT ATTR=id:ctl00_ContentPlaceHolder1_ddlReportOn&&TXT:* EXTRACT=HTM
    TAG POS R1 TYPE=option ATTR=value&&TXT
However, for every dropdown I would want to change just the **id** attribute, but for the code I tried it is just able to extract the text and not values from `<option..>` tag.

> p.s: http://briks.gov.in/Report/Rept_Building_Brik.aspx is the site from where I'm extracting data

Any suggestion on what changes should be made.
Any help would be much appreciated.
Thanks
Hum, I guess you didn't get my Reply in your previous Post...

But OK, for those interested, Advanced User @Shugar on SOF posted a Solution, no Follow-up from @OP either:
- Extracting attributes values dynamically imacros
answered Jul 31 at 8:00 by Shugar wrote:Try the following approach:

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=SELECT ATTR=id:ctl00_ContentPlaceHolder1_ddltype&&TXT:* EXTRACT=HTM
SET values1 EVAL("var v = '{{!EXTRACT}}'.match(/value=\"(.+?)\"/g).toString().replace(/value=\"|\"/g, '').split(','); v.shift(); v;")
PROMPT {{values1}}

SET !EXTRACT NULL
TAG POS=1 TYPE=SELECT ATTR=id:ctl00_ContentPlaceHolder1_ddlReportOn&&TXT:* EXTRACT=HTM
SET values2 EVAL("var v = '{{!EXTRACT}}'.match(/value=\"(.+?)\"/g).toString().replace(/value=\"|\"/g, '').split(','); v.shift(); v;")
PROMPT {{values2}}
(Perhaps someone may suggest something easier, but the code posted above seems to work anyway.)
@Shugar's Solution is indeed a bit cumbersome in my Opinion, and I would think not very easy to reuse for other Cases... But if it works, I guess @OP will be happy, ah-ah...!
I would have a much simpler Solution indeed (simpler in Implementation and simpler to understand/reuse for other Cases), hum maybe 2 Solutions, (but one is partially so simple that @Shugar must have considered it and there is probably some Caveat that I don't see without doing some Testing/Digging), that I may post one day if some other User has a similar Case (and posts and uses the Forum a bit more correctly than @OP from this Thread)... I've already posted the Principle in some other Thread btw...

But I'm still impressed a bit actually, woaw...! 'match()' + 'toString()' + 'replace()' + 'split()' + 'shift()' in one single 'EVAL()' Statement...! Not for "Cowards" I would think, ah-ah...!! 8)
- (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...
Post Reply