使用PhantomJS交易视图的屏幕截图

问题描述 投票:0回答:1

我正在尝试在我的服务器上呈现交易视图图表小部件的屏幕截图,类似于以下内容:

https://jsfiddle.net/exatjd8w/

我对PhantomJS并不熟悉,但是在加载后尝试了几种方法来拍摄图表,最后一次尝试使用以下代码:

var page = require('webpage').create();
page.open('https://mywebsite.com/chart', 
    function(status) {

        console.log("Status: " + status);

        if (status === "success") {
            page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function() {
                (page.evaluate(function() {
                  // jQuery is loaded, now manipulate the DOM
                      console.log('Status: jQuery is loaded, now manipulate the DOM');
                       var date = new Date(),
                           time = date.getTime()
                       $('#main-widget-frame-container iframe').on('load', function() {
                          console.log('iframe loaded, now take snapshot')
                          page.render('screenshot_' + time + '.png')
                       })
                }))
            })
        }
    }
);

不幸的是,由于上面的代码永远没有结果,所以仍然无法正确执行。

有什么想法,建议吗?

先感谢您。

javascript phantomjs tradingview-api
1个回答
0
投票

PhantomJS不再维护,并且有一些可能导致此问题的问题。我建议切换到Puppeteer,它有一个非常好的API,使用谷歌Chrome(无头)引擎盖,并由chrome团队积极维护:

https://github.com/GoogleChrome/puppeteer

© www.soinside.com 2019 - 2024. All rights reserved.