【发布时间】:2020-09-01 04:16:41
【问题描述】:
我开始使用 pupeteer 和 node 并在 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'
“No debug adapter, can't send 'variables'”是什么意思?
编辑:
我更新到最新的 vscode 并检查所有扩展是否都已更新。现在当我运行启动程序时
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
知道这意味着什么吗?
【问题讨论】:
-
调试适配器是连接调试器 API 和 VSC API 的工具。你能调试其他(简单)节点程序吗?
-
我以前从未使用过节点。我有一些客户端js经验,但以前主要在服务器端使用python。
-
按照 vsc 文档中的节点教程/设置进行操作
-
好的,调试器的行为与教程中的完全一样..
-
那么您的 webscraper 项目的设置与示例节点项目不同
标签: javascript node.js visual-studio-code puppeteer