Extracting attributes values dynamically imacros

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.

Extracting attributes values dynamically imacros

by deepesh on Fri Jul 28, 2017 9:36 pm

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
deepesh
 
Posts: 3
Joined: Fri Jun 30, 2017 11:44 pm

Re: Extracting attributes values dynamically imacros

by chivracq on Thu Aug 03, 2017 11:33 pm

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...
chivracq
 
Posts: 6481
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: chivracq and 4 guests

-->