常规iMacros转换为JavaScript但仍然无法工作

时间:2016-07-17 15:31:06

标签: javascript imacros

我不懂iMacros和初学者。实际上有常规的iMacro脚本正常工作,但我想根据需要制作成JavaScript,最多可循环17页(总页数),其中每页有10行数据需要提取。

这是我尝试过的但没有成功的。请帮忙,谢谢。

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');


    }
}

2 个答案:

答案 0 :(得分:1)

如果您不了解iMacros&#34;,我建议您到目前为止不建议使用JavaScript脚本接口。下面是在某种程度上模仿嵌套循环的代码。它必须以通常(循环)模式播放。我已经注意到可以调整这个模式给你工作的iim-code。尽量做到这一点。

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 '

答案 1 :(得分:1)

确保转义 和\字符。 您也可以使用此iMacros Java Script Converter