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 ?
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 ?
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.
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