【发布时间】:2020-09-29 23:06:40
【问题描述】:
我试过这个简单的例子来点击一个链接,但它似乎不起作用。 该示例基本上是单击 youtube.com 中的登录按钮 错误抛出
(node:12304) UnhandledPromiseRejectionWarning: TypeError: youtubeLoginButton.evaluate is not a function
at C:\Users\GoodBoy\Desktop\code\Puppeteer\scrape-content-from-website\bot.js:17:30
at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:12304) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise
which was not handled with .catch(). (rejection id: 1)
(node:12304) [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.
const puppeteer = require('puppeteer')
;(async () => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
args: ['--start-maximized'],
})
const page = await browser.newPage()
await page.goto('https://www.youtube.com/')
const youtubeLoginButtonXpath = '//*[@id="buttons"]/ytd-button-renderer/a'
const youtubeLoginButton = await page.$x(youtubeLoginButtonXpath)
await youtubeLoginButton.evaluate((form) => form.click())
await browser.close()
})()
【问题讨论】:
标签: javascript node.js xpath automation puppeteer