Regular iMacros transform into JavaScript but stil

2019-09-12 16:49发布

问题:

I do not understand iMacros, and beginners. Actually there are regular iMacro script is working properly, but I want to make into JavaScript as needed can be looping up to 17 pages (total page) where each page there are 10 rows of data to be extracted.

Here's what I tried but have not succeeded. Please help, thank you.

for(var PAGE = 1; PAGE <= 17; PAGE++)
{
    iimSet("page", PAGE)
    iimPlay('CODE:'+'SET !TIMEOUT_PAGE 50'+'\nURL GOTO=http://www.somebody-is-you.com/s/{{page}}?lim=10&reg_code=JINNY');
    iimPlay('CODE:'+'WAIT SECONDS=2');

    for(var POST = 1; POST <= 10; POST++)
    {
        iimPlay('CODE:'+'SET !REPLAYSPEED FAST');
        iimPlay('CODE:'+'SET !ERRORIGNORE YES');
        iimPlay('CODE:'+'SET !EXTRACT_TEST_POPUP NO');
        iimPlay('CODE:'+'SET !VAR1 {{!URLCURRENT}}');

        iimPlay('CODE:'+'TAG POS=1 TYPE=BUTTON FORM=ACTION:/agent/s ATTR=CLASS:dropdown-toggle EXTRACT=TXT');
        var DROPSHIP_AREA= iimGetLastExtract(1);

        iimPlay('CODE:'+'TAG POS={{!LOOP}} TYPE=A ATTR=CLASS:agent');
        iimPlay('CODE:'+'SET !VAR3 {{!URLCURRENT}}');
        iimPlay('CODE:'+'SET !EXTRACT {{!VAR3}}');

        iimPlay('CODE:'+'TAG POS=1 TYPE=H3 ATTR=TXT:* EXTRACT=TXT');
        iimPlay('CODE:'+'TAG POS=1 TYPE=SPAN ATTR=TXT:+62<SP>*');
        iimPlay('CODE:'+'TAG POS=1 TYPE=SPAN ATTR=TXT:+62<SP>* EXTRACT=TXT');
        var NO_HP= iimGetLastExtract(1);
        iimPlay('CODE:'+'TAG POS=1 TYPE=SPAN ATTR=CLASS:agency EXTRACT=TXT');
        var AGENCY= iimGetLastExtract(1);

        iimPlay('CODE:'+'SET !TIMEOUT_TAG 1');
        iimPlay('CODE:'+'TAG POS=1 TYPE=UL ATTR=CLASS:list-checked EXTRACT=TXT');
        var CHECKLIST_AREA= iimGetLastExtract(1);
        iimPlay('CODE:'+'TAG POS=1 TYPE=H1 ATTR=TXT:*<SP>Listing EXTRACT=TXT');
        var KERANJANG_BELANJA= iimGetLastExtract(1);
        iimPlay('CODE:'+'TAG POS=1 TYPE=A ATTR=CLASS:show-more&&HREF:#show-more*');
        iimPlay('CODE:'+'TAG POS=1 TYPE=DIV ATTR=CLASS:agent-de EXTRACT=TXT');
        var TTG_DETAIL_SIAGENT= iimGetLastExtract(1);
        iimPlay('CODE:'+'TAG POS=1 TYPE=A ATTR=TITLE:&&TARGET:_blank&&TXT:* EXTRACT=TXT');
        var LINK_WEB_SIAGENT= iimGetLastExtract(1).replace('/#EANF#/g', '');

        iimPlay('CODE:'+'TAG POS=1 TYPE=A ATTR=TARGET:_blank&&TXT:*.agent.fr/new');
        iimPlay('CODE:'+'TAB T=2');
        iimPlay('CODE:'+'SET !TIMEOUT_STEP 0');
        iimPlay('CODE:'+'TAG POS=1 TYPE=DIV ATTR=CLASS:a_addr&&TXT:* EXTRACT=TXT');
        var NO_HP_LAINNYA= iimGetLastExtract(1).replace('/#EANF#/g', '');
        iimPlay('CODE:'+'TAG POS=1 TYPE=DIV ATTR=CLASS:a_addr&&TXT:PIN<SP>* EXTRACT=TXT');
        var PIN_BBM= iimGetLastExtract(1).replace('/#EANF#/g', '');
        iimPlay('CODE:'+'TAG POS=1 TYPE=DIV ATTR=ID:a_info&&TXT:* EXTRACT=TXT');
        var CAMPUR_NAMA_EMAIL_BBM= iimGetLastExtract(1).replace('/#EANF#/g', '');
        iimPlay('CODE:'+'TAG POS=1 TYPE=DIV ATTR=CLASS:samsung-note-7&&STYLE:padding-top:* EXTRACT=TXT');
        var CAMPUR_HPHP= iimGetLastExtract(1).replace('/#EANF#/g', '');

        iimSet('dropship_area',DROPSHIP_AREA);
        iimSet('no_hp',NO_HP);
        iimSet('agency',AGENCY);
        iimSet('checklist_area',CHECKLIST_AREA);
        iimSet('keranjang_belanja',KERANJANG_BELANJA);
        iimSet('ttg_detail_siagent',TTG_DETAIL_SIAGENT);
        iimSet('link_web_siagent',LINK_WEB_SIAGENT);
        iimSet('no_hp_lainnya',NO_HP_LAINNYA);
        iimSet('pin_bbm',PIN_BBM);
        iimSet('campur_nama_email_bbm',CAMPUR_NAMA_EMAIL_BBM);
        iimSet('campur_hphp',CAMPUR_HPHP);

        iimPlay('CODE:\nADD !EXTRACT {{no_hp}}\nADD !EXTRACT {{agency}}\nADD !EXTRACT {{checklist_area}}\nADD !EXTRACT {{keranjang_belanja}}\nADD !EXTRACT {{ttg_detail_siagent}}\nADD !EXTRACT {{link_web_siagent}}\nADD !EXTRACT {{no_hp_lainnya}}\nADD !EXTRACT {{pin_bbm}}\nADD !EXTRACT {{campur_nama_email_bbm}}\nADD !EXTRACT {{campur_hphp}}\nSAVEAS TYPE=EXTRACT FOLDER=* FILE=result-{{dropship_area}}-JS.csv');

        iimPlay('CODE:'+'TAB OPEN NEW');
        iimPlay('CODE:'+'TAB T=2');
        iimPlay('CODE:'+'TAB CLOSEALLOTHERS');
        iimPlay('CODE:'+'URL GOTO={{!VAR1}}');
        iimPlay('CODE:'+'WAIT SECONDS=1');
        iimPlay('CODE:'+'SET !EXTRACT NULL');


    }
}

回答1:

If you "do not understand iMacros", I wouldn't advise to apply the JavaScript Scripting Interface so far. Below is the code that imitates nested loops to some extent. It must be played in usual (not loop) mode. I've noticed the possibility to adjust this pattern to you working iim-code. Try to do that.

SET numPages 17
SET numPosts 10

SET startLoop 1
SET maxLoop EVAL({{numPages}}*{{numPosts}})
SET !LOOP EVAL(1-{{maxLoop}}+{{startLoop}})
SET normLoop EVAL({{!LOOP}}+{{maxLoop}}-1)

SET curPage EVAL(~~(({{normLoop}}-1)/{{numPosts}})+1)
SET curPost EVAL({{normLoop}}%{{numPosts}}==0?{{numPosts}}:{{normLoop}}%{{numPosts}})

' do something according to the {{curPage}} and {{curPost}} values '


回答2:

Make sure to escape " and \ characters. You could also use this iMacros Java Script Converter