【问题标题】:Screenshot of Trading View Chart using PhantomJS使用 PhantomJS 的交易视图图表截图
【发布时间】:2019-03-09 10:48:55
【问题描述】:

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

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】:

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

    https://github.com/GoogleChrome/puppeteer

    【讨论】:

    • 太棒了,按预期工作。非常感谢约瑟夫 我一直在网上搜索并没有找到它。我将开始使用它,并找到一种使用 php 的方法。
    • @NaifAlghamdi 如果有帮助,请将其设置为已接受的答案 :)
    猜你喜欢
    • 2019-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 2013-06-15
    • 2014-10-21
    • 1970-01-01
    • 2022-08-05
    相关资源
    最近更新 更多