# 安装
# pip install pyppeteer
import asyncio from pyppeteer import launch async def main(): width, height = 1366, 768 # 有无界面设置 # 设置浏览器窗口大小 browser = await launch(headless=False, args=['--disable-infobars', f'--window-size={width},{height}']) # 启动一个新页面卡 page = await browser.newPage() # 设置显示屏幕窗口大小 await page.setViewport({'width': width, 'height': height}) # 运行Javascript,避免WebDriver被检测 await page.evaluateOnNewDocument('Object.defineProperty(navigator,"webdriver",{get:() => false})') # 打开一个网址 await page.goto('https://www.baidu.com') # 获取标题 t = await page.title() print(t) # 获取cookies c = await page.cookies() print(c) # 休眠5秒 关闭浏览器 await asyncio.sleep(5) await page.close() if __name__ == '__main__': asyncio.get_event_loop().run_until_complete(main())