【发布时间】:2017-10-27 20:31:38
【问题描述】:
我想从表中的每一行获取链接。这就是我获得第三名的方式(例如):
await page.evaluate(() => document.querySelector(#content-tabs-0 > div > table > tbody > tr:nth-child(3) > td.mpt-1-td-desc > a").href)
我想遍历表格行,我使用这样的代码:
for(let i=1;i<=10;i++){
let link = await page.evaluate(() => document.querySelector("#content-tabs-0
> div > table > tbody > tr:nth-child("+i+") > td.mpt-1-td-desc > a").href);
console.log(link);
}
当我执行代码时,我得到这样的错误:
(node:16928) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: ReferenceError: i is not defined
at <anonymous>:1:87
(node:16928) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.
应该如何正确做?
【问题讨论】:
标签: node.js web-scraping google-chrome-headless puppeteer