Мне нужно сделать снимок экрана простой веб-страницы, но ниже отображается ошибка, хотя я уже установил высоту.
Код: Выделить всё
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot take screenshot with 0 height."} (Session info: chrome=130.0.6723.58)
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.google.com'
driver.get(url)
desired_width = 1920
desired_height = 1080
page_body = driver.find_element(By.TAG_NAME,"body")
time.sleep(20)
page_body.screenshot("page_screenshot.png")
driver.quit()
Я тоже пробовал имея для моей переменной selected_height значение driver.execute_script("return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.client.Height,document.documentElement.scrollHeight,document.documentElement. offsetHeight);")
Я поискал здесь другие статьи и обнаружил, что задавалась аналогичная проблема, но на веб-странице, которую пытался получить веб-драйвер, есть разные капчи как мой. Мне буквально нужно сделать снимок экрана простой веб-страницы в формате HTML (предполагая, что это google.com) без каких-либо капч или необычных элементов безопасности, отображаемых на веб-странице.
Подробнее здесь: https://stackoverflow.com/questions/791 ... and-python