admin管理员组文章数量:1356908
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
本文标签: javascriptHow to take screenshot of a given url using pythonStack Overflow
版权声明:本文标题:javascript - How to take screenshot of a given url using python - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743983878a2571194.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论