gpt4 book ai didi

javascript - 将 Phantomjs 控制台传递给 php 文件

转载 作者:行者123 更新时间:2023-11-29 21:50:23 25 4
gpt4 key购买 nike

我一直在尝试将我的 phantomjs 控制台输出传递回执行它的 php 文件,但我只使用这段代码获取并清空数组。它也立即发生,这让我认为它试图在 phantomjs 脚本运行之前获得返回。

<?php
$user= 'dafjdh@kjsdf.com';
$pass='dumfmh';
$response = exec("/home/jef28/public_html/swipr/phantomjs /home/jef28/public_html/swipr/login.js $user $pass", $output);
echo $output;
?>

我的 .js 文件的最后几行是

console.log(document.querySelectorAll('html')[0].outerHTML);
return document.querySelectorAll('html')[0].outerHTML;

如何将控制台输出传回 php?

最佳答案

我使用了这个功能,它工作得很好。

function execute($script, $args = array(), $options = array(), $bin = 'F:/----/phantomjs-1.9.8-windows/phantomjs.exe', $debug = true) {

$option_str = '';
foreach ($options as $option => $value)
{
$option_str .= '--'.$option.'='.$value.' ';
}

// Escape
$cmd = escapeshellcmd("{$bin} {$option_str}{$script} " . implode(' ', $args));
if($debug) $cmd .= ' 2>&1';
// Execute
$result = shell_exec($cmd);
if($debug) return $result;
if($result === null) return false;

// Return
if(substr($result, 0, 1) !== '{') return $result; // not JSON
$json = json_decode($result, $as_array = true);
if($json === null) return false;
return $json;

}

关于javascript - 将 Phantomjs 控制台传递给 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29585010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com