I want to use selenium chrome to get the web screenshot, which just contains text but no images.
The chromedriver option param settings are:
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('no-sandbox')
options.add_argument('disable-dev-shm-usage')
options.add_argument('--disk-cache-dir=%s'%cache_path)
options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
browser = webdriver.Chrome(chrome_options=options)
the param "prefs", {"profile.managed_default_content_settings.images": 2}
is the way to disable images while using selenium chrome. Python: Disable images in Selenium Google ChromeDriver.
Then I want get the full screenshot, the codes show below:
browser.get(url)
original_size = browser.get_window_size()
width = browser.execute_script("return document.body.parentNode.scrollWidth")
height = browser.execute_script("return document.body.parentNode.scrollHeight")
browser.set_window_size(width, height)
element = browser.find_element_by_tag_name('body')
element_png = element.screenshot_as_png
with open(save_pic_path, "wb") as file:
file.write(element_png)
But the screenshot still contain images, so how to get the screenshot without images?