我的iMacro脚本没有在PHP脚本中运行。为什么?

我的iMacro脚本没有在PHP脚本中运行。为什么?,php,imacros,web-scripting,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($

我正在学习如何从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');


?>
另外,上述错误消息和iimfx.class.php中的MY_PROXY_IP和MY_PROXY_端口均替换为实际数字

下面是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' );

    }

}

?>

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


我觉得这个问题很有趣,我会用iMacro,但不会用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' );

    }

}

?>