async def main(self):
async with async_playwright() as p:
url = "..."
browser = await p.firefox.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
await asyncio.sleep(2)
print(await page.title())
for elem_main in list_of_categories_main:
async with async_playwright() as p:
await asyncio.sleep(2)
url = elem_main
browser = await p.firefox.launch(headless=False)
page = await browser.new_page()
await page.goto(url)
await asyncio.sleep(2)
await page.click(".pointer.help-city__btn.btn.btn-large.btn-primary")
await asyncio.sleep(2)
for (index, elem) in enumerate(list_of_categories):
async with async_playwright() as p:
url = elem
browser = await p.firefox.launch(headless=False)
page = await browser.new_page()
await page.goto(url)
await asyncio.sleep(1)
await page.click(".pointer.help-city__btn.btn.btn-large.btn-primary")
await asyncio.sleep(1)
while True:
try:
while await page.locator("#newBtnPager").is_visible() is False:
await page.mouse.wheel(0, 500)
while await page.locator("#newBtnPager").is_visible() is True:
await page.click("#newBtnPager")
categories_with_medicines_1 = (
await page.query_selector_all(".product-hor.mb-10.js-stateProduct"))
await browser.close()
break
except Exception as err:
print(err)
break
json_file = []
for i in categories_with_medicines_1:
data_id = await i.get_attribute('data-id')
print(data_id)
data_name = await i.get_attribute('data-name')
print(data_name)
data_url = await i.get_attribute('data-url')
print(data_url)
json_file.append({
'data_id': data_id,
'data_name': data_name,
'data_url': data_url
})
with open("info.json", "w") as file:
json.dump(json_file, file, indent=4, ensure_ascii=False)
print('Сохранил')
start = datetime.datetime.now()
r = exp()
asyncio.run(r.main())
print(datetime.datetime.now() - start)```