php - PhantomJS PHP exec()命令在浏览器中不起作用
问题描述
我正在使用 phantom JS 来获取网页的原始 HTML。当我使用终端但不在浏览器中时它正在工作。请参考照片:
exec("/Users/kaustubh/Desktop/phantomjs /Users/kaustubh/Desktop/loadspeed.js "."http://www.google.com ",$output);
var_dump($output);
我已经提到了许多类似的问题,结论与许可有关。
您如何看待这个错误?loadspeed.js的代码是:
var page = require('webpage').create(),system = require('system'),t, address;
if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit(1);
}else{
address=system.args[1];
var websiteAddress = address;
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113
Safari/537.36';
page.viewportSize = { width: 1920, height: 1080 };
page.clipRect = { top: 0, left: 0, width: 1920, height: 1080 }; page.open(websiteAddress, function (status) {
setTimeout(function(){
page.render('github.png');
console.log(returnChunksArray(page.content,6000));
phantom.exit();
}, 5000); // 5 sec should be enough
});
}
function returnChunksArray(str, chunkSize) {
var arr = [];
while(str !== '') {
arr.push(str.slice(0, chunkSize));
str = str.slice(chunkSize);
}
return arr;
}
就浏览器而言:浏览器甚至不等待exec()函数。我什至尝试了 shell_exec() 但没有成功。
但在终端中,它按预期加载。谢谢
解决方案
推荐阅读
- angular - 仅当我将鼠标悬停在其他页面组件上时才会加载 Angular 页面组件
- javascript - Robotframework:如何在我的网页上模拟选择
- c++ - GTest:使用“线程安全”样式时如何在死亡测试中将变量传递给分叉进程
- python - 如何创建电报组的排名
- google-cloud-platform - 如何在 Vertex AI AutoML 时间序列模型中选择目标列
- c# - IIS - 对象引用未设置为对象的实例 - System.Configuration.ConfigurationManager.GetSection
- html - 即使在导入后字体在 CSS 中也不会改变
- c# - 如何根据组合框和 numericupdown 的计算值在文本框中进行计算
- python - 在多个 URL 上使用 Beautiful Soup
- google-bigquery - 如何更新所有包含列且值与特定值匹配的大查询表?