A
A
andrew_shipunov2020-05-22 11:55:58
Python
andrew_shipunov, 2020-05-22 11:55:58

How to run it at the same time?

There is a code

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()
    for i in range(100):
        await page.goto('https://www.avito.ru/belgorod/nastolnye_kompyutery/sistemnyy_blok_1885815175')
        print('+1')
    # await page.screenshot({'path': 'example.png'})
    await browser.close()

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

And you need to make sure that it works in 1000 threads, and so that the system does not hang.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vkulik79, 2020-05-22
@andrew_shipunov

I can suggest this

import asyncio
from pyppeteer import launch

async def text():
  browser = await launch()
  page = await browser.newPage()
  await page.goto('https://www.avito.ru/belgorod/nastolnye_kompyutery/sistemnyy_blok_1885815175')
  print('+1')
    # await page.scre

async def main():
  tasks = [] # здесь будут все задачи

  for x in range(100): # запускаем 100 раз
    task = asyncio.create_task(text()) # создаем новый таск
    tasks.append(task) # и добавляем в наш общий список

  await asyncio.gather(*tasks) # распаковываем и запускаем

asyncio.run(main())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question