The log when executing phantomJS in python was a little annoying, so here's how to change the output destination.
from selenium import webdriver
#Specifying the driver
driver = webdriver.PhantomJS()
driver.set_window_size(1024, 768)
driver.get('https://google.com/')
#capture
driver.save_screenshot('google.png')
driver.quit()
It is saved as ghostdriver.log
under the current directory.
If you specify a path for service_log_path
, it will be output to that path.
log_name = '/tmp/phantomjs.log'
driver = webdriver.PhantomJS(service_log_path=log_name)
Specify phantomJS argument --webdriver-loglevel
in service_args
log_name = '/tmp/phantomjs.log'
driver = webdriver.PhantomJS(service_log_path=log_name,service_args=["--webdriver-loglevel=ERROR"])
You can check the arguments that can be passed to phantomJS with phantomjs -h
import os
import sys
driver = webdriver.PhantomJS(service_log_path=os.ttyname(sys.stdout.fileno()))
import os
driver = webdriver.PhantomJS(service_log_path=os.path.devnull)
Recommended Posts