Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript setTimeout不是';在PhantomJS中通过page.open访问t_Javascript_Phantomjs - Fatal编程技术网

Javascript setTimeout不是';在PhantomJS中通过page.open访问t

Javascript setTimeout不是';在PhantomJS中通过page.open访问t,javascript,phantomjs,Javascript,Phantomjs,我试图从页面调用nextpage函数。在脚本中打开,但当我运行此操作时,在控制台中没有输出,也没有错误。我已经调试了很长一段时间了,但没有任何解决方案。代码如下: var page = require('webpage').create(); var url = 'https://www.youtube.com/user/jannunzi/about'; page.open(url, function (status) { setTimeout(function(){

我试图从
页面调用
nextpage
函数。在脚本中打开
,但当我运行此操作时,在
控制台
中没有输出,也没有错误。我已经调试了很长一段时间了,但没有任何解决方案。代码如下:

var page = require('webpage').create();
var url = 'https://www.youtube.com/user/jannunzi/about';

page.open(url, function (status) {

    setTimeout(function(){
        nextpage();
        console.log("inside timeout.....");
    },5000);

    phantom.exit();
});

function nextpage(){
    console.log("huzefa...........................");
}

在这里,这两条控制台消息都不会在控制台中打印。

当您立即退出PhantomJS(
phantom.exit();
)时,它怎么能打印出来呢?JavaScript的
setTimeout()
是异步的,因此在调用回调之前对随后出现的语句进行求值。您应该将退出移动到回调中,以便调用
setTimeout()

thnx,救了我的命:),而我甚至不必为此学习医学。多大的成就啊