# 需要 pyppeteer.chromium_downloader
pip install websockets==7.0
# 默认安装driver路径
C:\Users\xxx\AppData\Local\pyppeteer\pyppeteer\local-chromium\chromdriver
# 匹配版本
pyppeteer == 0.0.25
chromdriver == 69.0.3494.0
# 必须使用循环事件
loop = asyncio.get_event_loop() # 启动函数
task = []
loop.run_until_complete(asyncio.wait(task))
brower = await launch(self.options)
# 当pyppeteer通过launch()或 连接到chrome时,会创建一个Browser对象connect()
page = await self.brower.newPage()
page.setViewport(viewport={'width': 1280, 'height': 800})
page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36")
await self.page.goto(self.login_url)
result = await self.page.xpath("//iframe[@id='J_loginIframe']/@src")
# 为list,如果需要提取信息,或点击,需要获取该 list 中得某一个元素进行
url = await (await target[0].getProperty('textContent')).jsonValue()
# xpath 匹配目标结果
await self.page.type('#TPL_username_1', self.username, {'delay': self.InputTimeRandom() - 50})
使用 css 查找器
'#TPL_u sername_1'
css 匹配
self.username
{'delay': self.InputTimeRandom() - 50}
await page.cookies()
await page.content()
await page.title()
await browser.close()
await (await item[0].getProperty('textContent')).jsonValue()
await (await item[0].getProperty('href')).jsonValue()
原文链接:http://pipe.b3log.org/blogs/AlwaysBeFriday/articles/2019/11/15/1575600976329