gpt4 book ai didi

node.js - puppeteer.use(....) 不是 Puppeteer 中的函数错误 - Nodejs

转载 作者:行者123 更新时间:2023-12-05 01:57:36 25 4
gpt4 key购买 nike

所以我正在尝试运行我的代码,但它显示此错误消息:-

(async () => {
^

TypeError: puppeteer.use(...) is not a function
at Object.<anonymous> (C:\Users\W\Desktop\top-auto\index.js:7:1)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47

我的代码:-

const puppeteer = require('puppeteer-extra')

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

(async () => {
const browser = await puppeteer.launch({ headless: true});
const page = await browser.newPage();
await page.setBypassCSP(true);
await page.goto("WEBSITE")
function login(token) {
setInterval(() => {
document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token = `"${token}"`;
}, 100);
setTimeout(() => {
location.reload();
}, 2500);
}
await page.addScriptTag({content: `${login}`})
await page.evaluate(t => login(t), "TOKEN")
})();

我使用的是 Windows 操作系统。并且我已经安装了运行代码所需的所有包,例如 npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth

最佳答案

(async 之前添加一个 ;,否则你会在上一行的表达式上编写一个函数调用。我建议使用 linter您将来会收到有关此的警告(请参阅 https://eslint.org/docs/rules/semihttps://eslint.org/docs/rules/no-unexpected-multiline )。

用一段简化的代码来说明这个问题:

const a = b

(() => {})()

... 这将失败并返回 b is not a function 因为它的解释如下:

const a = b(() => {})() 

这是因为自动分号插入只会在行尾假定一个分号,如果没有分号,代码在语法上是无效的——但在这个例子中它是完全有效的(尽管不是预期的)。因此,解决方案是始终在以 ([、` 或一元 +/-(后者无论如何都不是很有用):

const a = b

;(() => {})()

关于node.js - puppeteer.use(....) 不是 Puppeteer 中的函数错误 - Nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69087948/

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