在 PhantomJS 中使用 jQuery DOM 选择器语法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14265604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:24:34  来源:igfitidea点击:

Use jQuery DOM selector syntax in PhantomJS?

jqueryphantomjs

提问by larryq

I'm learning PhantomJS and wondered if it's possible to use jQuery DOM selectors in the JS files PhantomJS runs? I've seen a short example on github that appears to indicate this:

我正在学习 PhantomJS 并想知道是否可以在 PhantomJS 运行的 JS 文件中使用 jQuery DOM 选择器?我在 github 上看到了一个简短的例子,似乎表明了这一点:

Sample of PhantomJS with Qunit (and jQuery?)

带有 Qunit(和 jQuery?)的 PhantomJS 示例

If you look at the run-qunit.js file at the top it seems state you can use jQuery DOM selectors as parameters. But I'm getting errors when I do that-- not sure whether it's my syntax or because Phantom doesn't know about jQuery, so I thought I'd ask first about the PhantomJS/jQuery relationship.

如果您查看顶部的 run-qunit.js 文件,它似乎表明您可以使用 jQuery DOM 选择器作为参数。但是当我这样做时我遇到了错误——不确定是我的语法还是因为 Phantom 不了解 jQuery,所以我想我会先询问 PhantomJS/jQuery 关系。

回答by Sandip Mondal

Use page.injectJs('jquery-1.6.1.min.js'); it will work fine.

使用 page.injectJs('jquery-1.6.1.min.js'); 它会正常工作。

here is a beautiful link for using jquery in phantomjs http://snippets.aktagon.com/snippets/534-how-to-scrape-web-pages-with-phantomjs-and-jquery

这是在 phantomjs 中使用 jquery 的漂亮链接 http://snippets.aktagon.com/snippets/534-how-to-scrape-web-pages-with-phantomjs-and-jquery

回答by vg7g465sd7654

There is people telling that documentation samples loading JQuery are buggy and load JQuery on PhamtomJS is impossible here: loading jquery on phanthomjs

有人说加载 JQuery 的文档样本有问题,在 PhamtomJS 上加载 JQuery 是不可能的:loading jquery on phanthomjs

回答by larryq

..well, as soon as I posted, I (naturally) found this. Looks like it is possible in fact to include jQuery:

..好吧,我一发帖,我(自然地)发现了这个。看起来实际上可以包含 jQuery:

https://github.com/ariya/phantomjs/wiki/Page-Automation

https://github.com/ariya/phantomjs/wiki/Page-Automation