gpt4 book ai didi

javascript - .inject()和.goto()方法在 Nightmare 中不起作用

转载 作者:行者123 更新时间:2023-12-03 13:23:46 24 4
gpt4 key购买 nike

我已经用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()
我需要怎么做才能加载页面?也许没有足够的时间?

最佳答案

我认为

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

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

您缺少报价

关于javascript - .inject()和.goto()方法在 Nightmare 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57010128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com