python pyppeteer 强制点击 Jeval

import pyppeteer
import asyncio


async def main():
    browser = await pyppeteer.launch(headless=False, userDataDir='./userdata', args=['--disable-infobars'])
    page = await browser.newPage()
    await page.setViewport({'width': 1366, 'height': 768})
    await page.evaluateOnNewDocument('Object.defineProperty(navigator,"webdriver",{get:()=>undefined})')
    await page.goto('https://www.bilibili.com')

    await page.waitForSelector('.unlogin-avatar')
    await page.click('.unlogin-avatar')

    await page.waitForSelector('.login-btn')
    # 强制点击, 用一般的方法无法点击
    await page.Jeval('.login-btn', 'node => node.click()')


    await asyncio.sleep(100)
    

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())

上一篇:C#使用异步操作时的注意要点(翻译)


下一篇:异步编程之在await前后线程的变化(1)