0

I want to save a web page as a picture with python but I don't know how to do.

Is there any package (or open-source software) could help me ?

  • here're [several code examples to get the screenshot of a web page (calling chrome as external command, driving headless chrome using selenium, driving firefox using marionette, and pyppeteer for chrome (text in Russian, code in Python)](https://ru.stackoverflow.com/a/821319/23044) – jfs Jul 05 '18 at 19:36

2 Answers2

1

You could use (or inspect the code from) pywebshot, an open source tool that seems to do exactly what you need.

$ ./pywebshot.py -t 500x250 http://stackoverflow.com http://meta.stackoverflow.com
Loading http://stackoverflow.com... saved as stackoverflow.com.png
Loading http://meta.stackoverflow.com... saved as meta.stackoverflow.com.png
anon582847382
  • 19,907
  • 5
  • 54
  • 57
1

You could use selenium webdriver to get a screenshot in different browsers e.g., in Chrome:

#!/usr/bin/env python
from selenium.webdriver import Chrome

url, filename = 'http://www.stackoverflow.com', '/tmp/stackoverflow.com.png'

browser = Chrome()
try:
    browser.get(url)
    browser.get_screenshot_as_file(filename)
finally:
    browser.quit()

xvfb allows to run selenium headlessly (without GUI) if you want to take many screenshots in parallel. See also Is it possible to run selenium (Firefox) web driver without a GUI?.

Note: there is a bug chrome driver 2 makes screenshot just of visible part of page. See workarounds there.

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670