Я загружаю страницу и успешно нажимаю кнопку загрузки с помощью Playwright. Откроется диалоговое окно печати с выбранным принтером.

Я хотел бы выбрать «Сохранить как PDF», а затем нажать кнопку «Сохранить».
Вот мой текущий код:
Код: Выделить всё
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
playwright_page = browser.new_page()
got_error = False
try:
playwright_page.goto(url_to_start_from)
print(playwright_page.title())
html = playwright_page.content()
except Exception as e:
print(f"Playwright exception: {e}")
got_error = True
if not got_error:
soup = BeautifulSoup(html, 'html.parser')
#download pdf
with playwright_page.expect_download() as download_info:
playwright_page.locator("text=download").click()
download = download_info.value
path = download.path()
download.save_as(DOWNLOADED_PDF_FOLDER)
browser.close()
Подробнее здесь: https://stackoverflow.com/questions/723 ... int-to-pdf