带有查询字符串的URL的PhantomJS页面加载失败

带有查询字符串的URL的PhantomJS页面加载失败,phantomjs,Phantomjs,我正在用PhantomJS 2.1.1打开一个本地html文件。我想使用查询字符串向页面传递一个值 这是我的密码: var args = require('system').args; args.forEach(function(arg, i) { console.log(i+'::'+arg); }); var page = require('webpage').create(); page.viewportSize = { width: 1000, height: 800 };

我正在用PhantomJS 2.1.1打开一个本地html文件。我想使用查询字符串向页面传递一个值

这是我的密码:

var args = require('system').args;
args.forEach(function(arg, i) 
{
    console.log(i+'::'+arg);
});

var page = require('webpage').create();
page.viewportSize = { width: 1000, height: 800 };

page.onConsoleMessage = function(msg)
{
  console.log(msg);
}

//var postBody = 'dataLoc='+args[2];
//page.open('///'+args[1], 'POST', postBody, function(status)

//page.open('///'+args[1]+'?dataLoc='+args[2], function(status)
page.open('///'+args[1], function(status)
{
    console.log("Status: " + status);

    var url = page.url;
    console.log('URL: ' + url);

    var clipRect = page.evaluate(function()
    {
       return document.querySelector("div#map").getBoundingClientRect();
    });
});
我省略了注释行以显示我的尝试。使用页面文件名的传入参数打开页面有效(这是一个未注释掉的参数)。以帖子的形式打开页面是可行的,但是当我查看window.location.search时,页面上的查询字符串不可用。将查询字符串作为URL的一部分打开页面将完全失败。如果我直接在浏览器中打开带有查询字符串的URL,那么当我登录到控制台时,我会在window.location.search中看到它

当我尝试将查询字符串直接放入url时,控制台上出现以下错误:

C:\phantomjs-2.1.1-windows\bin>phantomjs.exe .\public\openPagePhantomJS.js c:/phantomjs-2.1.1-windows/bin/public/testHeatMap.html testParam
0::.\public\openPagePhantomJS.js
1::c:/phantomjs-2.1.1-windows/bin/public/testHeatMap.html
2::testParam
Status: fail
URL:
ERROR: TypeError: null is not an object (evaluating 'document.querySelector("div#map").getBoundingClientRect')
TRACE:
 -> undefined: 2
 -> : 3

  phantomjs://code/openPagePhantomJS.js:49 in onError

因此,实际上根本没有加载页面。如果你能做到这一点,谢谢。有什么给我的建议吗?我对PhantomJS的体验水平很低。

尝试控制台。记录您打开的url,是否有打字错误?感谢Vaviloff的建议,但url很好。尝试在url页面的开头添加
文件:
,就这样!多谢各位