How to run PhantomJS with command line options in Selenium?

I cannot find how to start phantomjs with command line options like --cookies-file=/path/to/cookies.txt and others ...

I tried driver = webdriver.PhantomJS('--cookies-file=/tmp/ph_cook.txt') , but nothing.

For an unknown reason add_cookie does not work to log.

I tried to run phantomjs as follows:

 driver = webdriver.PhantomJS(executable_path = "phantomjs --cookies-file=/tmp/ph_cook.txt --webdriver") 

but getting an error:

 raise WebDriverException("Unable to start phantomjs with ghostdriver.", e) selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghost driver. 
+5
source share
1 answer

You can pass command line arguments to the PhantomJS instance behind the scenes by passing them as a list to the service_args argument:

 webdriver.PhantomJS(service_args=['--cookies-file=/tmp/ph_cook.txt']) 

If the driver cannot be started, language bindings will probably not be able to correctly locate the PhantomJS executable. You may need to optionally pass the full path to the executable_path argument. Please note that if you installed PhantomJS through npm, the actual executable is not located directly in the global package directory, but in its subfolder.

+7
source

Source: https://habr.com/ru/post/1209740/


All Articles