Код: Выделить всё
async def get_goods_from_pages(session, page):
url = f'https://somewebsite?page={page}'
async with session.get(url, headers=headers) as r:
soup = BS(await r.text(), 'lxml')
all_goods = soup.find_all('div', class_='js_category-list-item')
print(r.read())
if all_goods:
for el in all_goods:
print(el)
else:
raise SomeError
# collect all tasks function
async def get_pages_info():
tasks = []
async with aiohttp.ClientSession() as session:
for page in range(1, 150):
task = asyncio.create_task(get_goods_from_pages(session, page))
tasks.append(task)
try:
group = asyncio.gather(*tasks)
await group
except Exception:
group.cancel()
Подробнее здесь: https://stackoverflow.com/questions/782 ... i-dont-kno