PhantomJS 无法通过测试从 html 页面正确加载脚本

发布于 2025-01-05 09:31:18 字数 386 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2025-01-12 09:31:18

有同样的问题,看起来像是 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文