【问题标题】:PhantomJS not running Javascript [duplicate]PhantomJS 没有运行 Javascript [重复]
【发布时间】:2016-07-13 04:54:23
【问题描述】:

我有一个 html 页面,可以在本地 xampp 的帮助下访问,http://localhost/testingserver/trelloapi.html

该页面看起来像这样,当在 chrome 中打开时,该页面加载正常,并且在我的 trello 列表中创建了一张卡片。我换掉了 my_key 等,所以在我的版本中,我有一个很长的 12345abcsd ...

trelloapi.html

<!DOCTYPE html>
 <html>
  <head>
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="https://api.trello.com/1/client.js?key={my_key}&token={my_token}"></script>
  </head>
 <body>

<script type="text/javascript">

var myList = "{my_listId}";
var creationSuccess = function(data) {
  console.log('Card created successfully. Data returned:' +   JSON.stringify(data));
};
var newCard = {
  name: 'Making card from console 0.o', 
  desc: 'This is the description of our new card.',
  // Place this card at the top of our list 
  idList: myList,
  pos: 'top'
};
Trello.post('/cards/', newCard, creationSuccess);
</script>
</body>
</html>

但是当我使用带有以下代码的 PhantomJS 时,不会在 Trello 上创建来自 http://phantomjs.org/ 的卡片

phantomcall.js

// Simple Javascript example
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://localhost/testingserver/trelloAPI.html';
page.open(url, function (status) {
  console.log(status);
  //Page is loaded!
  phantom.exit();
});

我下载了包含 bin/phantomjs 的 phantomjs-2.1.1-macosx.zip 并在终端中使用命令: $ sudo ./phantomjs ../../../Desktop/testingServer/phantomcall.js

在控制台中打印以下内容:

加载网页

成功

【问题讨论】:

  • 网站加载成功,但页面可能有错误。尝试返回页面文档phantomjs.org/quick-start.html
  • 当我在浏览器中打开页面时,在控制台中我得到“卡创建成功。数据返回:{“id”:“56f5....”,“徽章”:.... "(长 json 响应)没有错误。我得到了一张在 Trello 中创建的新卡片。
  • 可能 phantomjs 没有等待“完整”页面加载 - stackoverflow.com/questions/11340038/…
  • 很棒的 Yevgeniy,成功了。发布您的答案并标记它

标签: javascript html terminal phantomjs trello


【解决方案1】:

我认为在使用 javascript 时确保页面已完全加载应该是一个好习惯。所以,答案可能就在这里:phantomjs not waiting for "full" page load

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    相关资源
    最近更新 更多