Introduction of pyppeteer

The official document links

Official Example:

import asyncio
from pyppeteer import launch

async def main():
  bro=await launch()
  page=await bro.newPage()
  await page.goto("https://www.baidu.com")
  await page.screenshot({'path':'example.png'})
  await bro.close()

asyncio.get_event_loop().run_until_complete(main())

1 flow analysis:

the async - declare an asynchronous operation

the await - to declare a time-consuming operation

asyncio.get_event_loop () run_until_complete (main ()).- create and perform the main function of asynchronous pool

= Launch the await Bro () - create a browser object, (a dictionary can be passed parameters)

the await bro.newPage = Page () - create a page object, page operation is performed on the object

page.goto the await ( "http://www.baidu.com") - the page jump

page.screenshot the await ({ 'path': 'example.png'}) --png saved to the specified directory in the form of theme

browser.close the await () - Close the browser objects

 

2 launch common configuration

browesr = await launch({})接受字典形式的关键字配置,也可以直接接受键值对的方式进行配置。

Placement name Value Type description
ignorehttpserrrors bool Ignore https error, default false
headless bool Is visible
viewport dict Screen sizeviewport={'width': 1280, 'height': 800}
args list[str] Additional parameters (mark) process
userDataDir str User data directory path
devtools bool Punch panel, the effect is the same headless
log level (int str) Print log level logs. The default root logger.

To be perfect

 

Guess you like

Origin www.cnblogs.com/codexlx/p/12582263.html