I'm trying to take a screenshot from the given URL. Tried html2canvas library in javascript, dropped off since it doesn't support some CSS formats. Now trying to capture the screenshot of the given URL using python and selenium or any other libraries if possible.
I have gone through the previous solutions and what I have faced is,
1.pyqt4 - Facing No module named 'PyQt4.QtWebKit'error even after installing pyqt4
2.selenium -The code not taking the screenshot of the entire page scroll.
3.phantom.js - Gives floating-point dumped error for some website
sample code for selenium :
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless") # Runs Chrome in headless mode.
options.add_argument('--no-sandbox') # # Bypass OS security model
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path='./chromedriver')
driver.get('')
driver.save_screenshot('screenshot-headless.png')
driver.quit()
Environment:
OS :ubuntu 18.04
python :3.6
Expected output :(Any one)
1.Dataurl of the image captured
2.Captured image (through out the scroll)
What was the problem with my code? Are there any alternatives ?
I'm trying to take a screenshot from the given URL. Tried html2canvas library in javascript, dropped off since it doesn't support some CSS formats. Now trying to capture the screenshot of the given URL using python and selenium or any other libraries if possible.
I have gone through the previous solutions and what I have faced is,
1.pyqt4 - Facing No module named 'PyQt4.QtWebKit'error even after installing pyqt4
2.selenium -The code not taking the screenshot of the entire page scroll.
3.phantom.js - Gives floating-point dumped error for some website
sample code for selenium :
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless") # Runs Chrome in headless mode.
options.add_argument('--no-sandbox') # # Bypass OS security model
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path='./chromedriver')
driver.get('https://stackoverflow./questions/51000899/better-way-to-take-screenshot-of-a-url-in-python')
driver.save_screenshot('screenshot-headless.png')
driver.quit()
Environment:
OS :ubuntu 18.04
python :3.6
Expected output :(Any one)
1.Dataurl of the image captured
2.Captured image (through out the scroll)
What was the problem with my code? Are there any alternatives ?
Share Improve this question asked Dec 13, 2019 at 11:38 Gomathimeena SubburayanGomathimeena Subburayan 5052 gold badges10 silver badges21 bronze badges1 Answer
Reset to default 9Did you try use Pyppeteer https://github./miyakogi/pyppeteer?
With fullPage
parameter you can take a screenshot of the entire page.
import asyncio
from pyppeteer import launch
async def main():
browser = await launch(headless=True)
page = await browser.newPage()
await page.goto('https://stackoverflow./questions/51000899/better-way-to-take-screenshot-of-a-url-in-python')
await page.screenshot({'path': 'screen.png', 'fullPage': True})
await browser.close()
asyncio.get_event_loop().run_until_plete(main())
EDIT
https://github./miyakogi/pyppeteer is not maintained. New project: https://github./pyppeteer/pyppeteer