.inject()和.goto()方法不适用于噩梦

时间:2019-07-12 15:40:29

标签: javascript nightmare

我已经用Nightmare抓了几天了,我的问题是加载页面并使用jQuery包含.inject() 我写了这段代码;

const Nightmare = require ('nightmare');
var nightmare = new Nightmare ();

nightmare
    .goto(url)
    .inject('js', __dirname + /jquery.min.js')
    .evaluate(fn(){
               /*I need to extract some information from the page but when 
               I try to use the DOM object or the jQuery's '$' it shows 
               me an error saying that no document is defined*/
     })
    .wait(500);

PHPstorm(我使用JS和PHP编程的IDE)标记.goto().inject()并放下警告消息unresolved function or method .goto()unresolved function or method .inject()

我需要做什么来加载页面?也许没有足够的时间?

1 个答案:

答案 0 :(得分:0)

我认为

.inject('js', __dirname + /jquery.min.js')' 

应该是

.inject('js', __dirname + '/jquery.min.js')'

您缺少报价