我开始使用 pupeteer 和节点,并在 win 10 中使用 vscode。我正在尝试登录一个站点并抓取一个表。到目前为止我有:
(async () => {
const browser = await puppeteer.launch({
headless: false,
});
var page = await browser.newPage();
await page.goto('thesite.com/login/');
await page.click(USERNAME_SELECTOR);
await page.keyboard.type(CREDS.username);
await page.click(PASSWORD_SELECTOR);
await page.keyboard.type(CREDS.password);
await page.click(BUTTON_SELECTOR);
await page.waitForNavigation();
const TABLE_ROW_SELECTOR = '.gv-container.gv-container-133 > table > tbody';
await page.waitForSelector(TABLE_ROW_SELECTOR);
await page.waitForSelector(TABLE_ROW_SELECTOR);
await page.screenshot({ path: 'example.png' });
const data = await page.evaluate(SELECTOR => document.querySelectorAll(SELECTOR), TABLE_ROW_SELECTOR);
await browser.close();
})();
这主要是工作。但是在我的控制台中,我看到了一个对象列表,但据我所知没有任何值。这是最重要的对象:
0:Object {}
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , …}
__defineGetter__:function __defineGetter__() { … }
__defineSetter__:function __defineSetter__() { … }
__lookupGetter__:function __lookupGetter__() { … }
__lookupSetter__:function __lookupSetter__() { … }
constructor:function Object() { … }
hasOwnProperty:function hasOwnProperty() { … }
No debug adapter, can not send 'variables'
isPrototypeOf:function isPrototypeOf() { … }
No debug adapter, can not send 'variables'
“没有调试适配器,无法发送‘变量’”是什么意思?
编辑:
我更新到最新的 vscode 并检查所有扩展是否已更新。现在当我运行 LAUNCH PROGRAM
E:\nodejs\node.exe --inspect-brk=27108 index.js
Debugger listening on ws://127.0.0.1:27108/e5928c71-370c- 4111-9ec3-77bb2cd85075
For help, see: https://nodejs.org/en/docs/inspector
(node:12844) ExperimentalWarning: The fs.promises API is experimental
warning.js:18
Array(25) [ElementHandle, ElementHandle, ElementHandle, ElementHandle, ElementHandle, ElementHandle, ElementHandle, ElementHandle, …]
index.js:64
length:25
__proto__:Array(0) [, …]
concat:function concat() { … }
[[Scopes]]:Scopes[0]
arguments:TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
知道这意味着什么吗?
原文由 user1592380 发布,翻译遵循 CC BY-SA 4.0 许可协议
I had this issue when trying to use the
integratedConsole
rather thanintegratedTerminal
orexternalTerminal
as part of my Node configuration withinlaunch.json
:将其设置回:
解决它。只花了一个小时就弄明白了。有关详细信息,请参阅 文档。