我的iMacro脚本)不在我的PHP脚本中运行。为什么?

时间:2013-02-25 23:42:11

标签: php imacros web-scripting

我正在学习如何从我的PHP脚本运行iMacros,以便PHP脚本调用iMacros浏览器会话并传递我拥有的任何变量(例如url和宏名称)。然后iMacros会话运行iMacro,在宏完成运行后,它将生成的html页面传递回PHP脚本并自行关闭。无论如何,在一个理想的世界里。

这是iMacros调用脚本:

<?php

require 'src/iimfx.class.php';

$iim = new imacros();

$vars = array();

$iim->play($vars,'grab_data.iim');


?>

但是当我从WAMP上的cmd.exe [命令行]运行这个脚本时,我得到了这个:

New imacros session started!
Using Proxy: MY_PROXY_IP:MY_PROXY_PORT
-runner -fx -fxProfile default
--------------------------------------------------------
Setting Value IP => MY_PROXY_IP
Setting Value port => MY_PROXY_PORT
Playing Macro proxy.iim
--------MACRO ERROR!-------------------
 ERROR: Browser was not started. iimInit() failed?
--------------------------------------------------------
Playing Macro grab_google.iim
--------MACRO ERROR!-------------------
 ERROR: Browser was not started. iimInit() failed?

P.S。上面的错误消息和iimfx.class.php中的MY_PROXY_IP和MY_PROXY_PORT都替换为实际数字。

这是iimfx.class.php的代码:

<?php

class imacros {
    function __construct($proxyip = 'MY_PROXY_IP', $proxyport = 'MY_PROXY_PORT', $silent = false, $noexit = false) {

        echo "--------------------------------------\nNew imacros session started!\nUsing Proxy: $proxyip:$proxyport\n";
        $this->proxyip = $proxyip;
        $this->proxyport = $proxyport;

        if (empty ( $this->proxyip ))
            echo "NO PROXY!!\n";

        $this->noexit = $noexit;
        $this->fso = new COM ( 'Scripting.FileSystemObject' );
        $this->fso = NULL;

        $this->iim = new COM ( "imacros" );

        $toexec = "-runner -fx -fxProfile default";

        if ($silent === true)
            $toexec .= " -silent";

        if ($noexit === true)
            $toexec .= " -noexit";

        echo $toexec . "\n";

        $this->iim->iimInit ( $toexec );

        if (! empty ( $this->proxyip )) {
            $dvars ['IP'] = $this->proxyip;
            $dvars ['port'] = $this->proxyport;
            $this->play ( $dvars, 'proxy.iim' );
        }
    }

    function __destruct() {
        if ($this->noexit === false)
            $this->iim->iimExit ();
    }

    function play($immvars = '', $macro) {

        echo "--------------------------------------------------------\n";

        if (is_array ( $immvars )) {
            foreach ( $immvars as $key => $value ) {
                echo "Setting Value $key => $value\n";
                $this->iim->iimSet ( "-var_" . $key, $value );
            }
        }

        echo "Playing Macro $macro\n";
        $s = $this->iim->iimPlay ( $macro );

        if($s>0){
            echo "Macro successfully played!\n";
        }else{
            echo "--------MACRO ERROR!-------------------\n ERROR: " . $this->getLastError() . "\n";
        }
        return $s;
    }

    // This function retrieves extracts in your iMacros script if you have any. 
    function getLastExtract($num) {
        return $this->iim->iimGetLastExtract ( $num );
    }

    // Returns the last error :)
    function getLastError(){
        return $this->iim->iimGetLastError();
    }

    // Enables/disables images
    function setImages($images = 1) { // 1 = on 2 = off

        $dvars ['images'] = $images;
        $this->play ( $dvars, 'images.iim' );

    }

    // Enables or disables adblockplus
    function enableABP($status = true){

        $dvars['status'] = $status;
        $this->play ( $dvars, 'abp.iim' );

    }

}

?>

我在这里缺少什么吗? 我在所有这些[运行脚本之前手动启动]运行iimRunner.exe并且我有iMacros Browser V8 +。 另外,我的grab_data.iim和所有其他必需的.iim与试图调用它们并执行它们的php脚本在同一个地方。

任何形式的帮助和/或向正确的方向转向都将非常感激!! 提前谢谢。

1 个答案:

答案 0 :(得分:-1)

U必须在启动脚本之前启动immrunner =)

http://wiki.imacros.net/iimRunner