赞
踩
Puppeteer 是 Chrome 开发团队在 2017 年发布的一个 Node.js 包,用来模拟 Chrome 浏览器的运行。
Most things that you can do manually in the browser can be done using Puppeteer
- import asyncio
- from turtle import width
- from pyppeteer import launch
-
- async def main():
- # launch chromium browser in the background
- browser = await launch()
- # open a new tab in the browser
- page = await browser.newPage()
- # add URL to a new page and then open it
- await page.goto("https://www.amazon.com/s?k=cattree&crid=2BDJM8GZOOEQ3&sprefix=cattree%2Caps%2C682&ref=nb_sb_noss_2")
- # create a screenshot of the page and save it
- await page.setViewport({'width':1200,'height':8000})
- await page.screenshot({"path": "python.png"})
- # close the browser
- await browser.close()
-
- print("Starting...")
- asyncio.get_event_loop().run_until_complete(main())
- print("Screenshot has been taken")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。