Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Coffeescript PhantomJS具有多个页面的意外加载行为_Coffeescript_Phantomjs - Fatal编程技术网

Coffeescript PhantomJS具有多个页面的意外加载行为

Coffeescript PhantomJS具有多个页面的意外加载行为,coffeescript,phantomjs,Coffeescript,Phantomjs,我有一个脚本(见下文),它通过三个步骤来完成一个站点的创建。当设置为一次最多1页时,效果非常好。然而,当我一次增加到2时,事情开始变得不稳定。onFinished比我预期的要早,页面还没有完全加载。因此,我的脚本的其余部分中断。知道为什么会这样吗?我应该补充一点,我使用的是最新版本(1.5) 我认为问题在于PhantomJS中的每个网页都使用相同的QNetworkAccessManager,因此,当每个网页对象完成加载时,信号就会触发。为了解决这个问题,可能需要修改PhantomJS的代码。我以

我有一个脚本(见下文),它通过三个步骤来完成一个站点的创建。当设置为一次最多1页时,效果非常好。然而,当我一次增加到2时,事情开始变得不稳定。onFinished比我预期的要早,页面还没有完全加载。因此,我的脚本的其余部分中断。知道为什么会这样吗?我应该补充一点,我使用的是最新版本(1.5)


我认为问题在于PhantomJS中的每个网页都使用相同的QNetworkAccessManager,因此,当每个网页对象完成加载时,信号就会触发。为了解决这个问题,可能需要修改PhantomJS的代码。我以前在PhantomJS中尝试并行加载多个页面时注意到了这一点。我正在使用的应用程序使用QtWebkit并同时加载多个页面,因此我必须确保每个页面都有自己的QNetworkAccessManager,以便完成的()信号不会相互干扰。

要抓取多个页面,请参阅与库捆绑的示例follow.js


在加载下一页之前,您需要使用递归等待当前页加载。

如果不是本例中的递归调用,则至少有一个将触发下一次爬网的回调。您的链接已断开:(
MAX_PAGES = 1
### 
changing MAX_PAGES to >1 causes some pages onFinished event to fire before
the page is fully rendered.  this is evident by the fact that there are >1 images
for some pages.  i havent been able to reproduce using microsoft.com, but on some
pages i was working on the first onLoadFinished seemed to be called before the page
was actually fully loaded based on the look of the rendered images
###

newPage = (id) ->
context = {}
context.id = id
context.step = 0
context.page = require('webpage').create()
context.page.onLoadStarted = ->
    context.step++
context.page.onLoadFinished = (status) ->
    console.log status
    if status is 'success'
        context.page.render("#{context.id}_#{context.step}.png")
    else
        context.page.release()
        context.page.open('http://www.microsoft.com')
        console.log 'started loading'

newPage id for id in [1..MAX_PAGES]