PhantomJS 无法通过测试从 html 页面正确加载脚本
PhantomJS 没有加载脚本,因为它尝试在以下路径加载它们:file:///[html 文件中指定的 src]。在 html 文件中,脚本的路径是相对的,我不想将它们设置为绝对路径(正在按照此示例 进行操作http://thomasardal.com/tag/phantomjs/)。因此,例如在 html 页面中,我有 并且 PhantomJS 尝试加载它来自 file:///jquery-1.7.0.js 不存在。如何让PhantomJS从正确的路径加载脚本?
PhantomJS is not loading scripts, because it tries to load them at the following path: file:///[src specified in html file]. In html file the paths to the scripts is relative, and I do not want to make them absolute (was doing following this example http://thomasardal.com/tag/phantomjs/). So, for example in html page I have <script type="text/javascript" src="jquery-1.7.0.js"></script>
and PhantomJS tries to load it from file:///jquery-1.7.0.js which is not exists. How to get make PhantomJS load scripts from the correct path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有同样的问题,看起来像是 phantomjs 中的一个错误。
找到了解决该问题的一种方法:
在 page.open 函数中,您可以调用 page.injectJs(FILENAME) - 并且 FILENAME 似乎使用与执行路径或 page.libraryPath 相对的路径(默认为第一个路径) js arg 位于)
Have the same issue and would seem like a bug in phantomjs.
Found one way to get around the issue:
Inside your page.open function you can call page.injectJs(FILENAME) - and FILENAME would appear to work with a path relative from the execution path or page.libraryPath (which defaults to where the first js arg is located)