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?
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()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With