Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to render a webpage directly to an image in python?

Now I am using selenium to save a web page to image.

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("some url")
browser.save_screenshot(img)
browser.quit()

But there is a problem that each time it will popup a window.

Is there any way that can render a image directly to an image?

like image 794
camino Avatar asked Nov 27 '13 19:11

camino


2 Answers

I found a workaround at How do I run Selenium in Xvfb?

It works fine in linux.

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get("some url")
browser.save_screenshot(img)
browser.quit()
display.stop()
like image 54
camino Avatar answered Nov 12 '22 05:11

camino


You can use phantomjs

Here you can find a good tutorial: http://www.realpython.com/blog/python/headless-selenium-testing-with-python-and-phantomjs/#.UtFpiXMuKAg

like image 24
Andrea de Marco Avatar answered Nov 12 '22 07:11

Andrea de Marco