所以我尝试运行我的代码,但它显示此错误消息:-
(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
Run Code Online (Sandbox Code Playgroud)
我的代码:-
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")
})();
Run Code Online (Sandbox Code Playgroud)
我使用的是 Windows 操作系统。我已经安装了运行代码所需的所有软件包,例如npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth
;在 之前添加(async,否则您将在上一行的表达式上编写函数调用。我建议使用 linter,以便您将来收到有关此问题的警告(请参阅https://eslint.org/docs/rules/semi和https://eslint.org/docs/rules/no-unexpected-multiline)。
用一段简化的代码来说明这个问题:
const a = b
(() => {})()
Run Code Online (Sandbox Code Playgroud)
...这将失败,b is not a function因为它的解释如下:
const a = b(() => {})()
Run Code Online (Sandbox Code Playgroud)
这是因为自动分号插入只会在行尾假定一个分号,如果没有分号,代码在语法上将无效 - 但在本例中它是完全有效的(尽管不是预期的)。(因此,解决方案是始终在以、[、 ` 或一元+/开头的行之前插入分号-(无论如何,后者实际上并不是很有用):
const a = b
;(() => {})()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5534 次 |
| 最近记录: |