1

I am trying to send cookies to phantomjs while starting the driver phanton.add_cookie({}) works.

I want to keep a list of cookies in a file and pass them as arguments while launching phantomjs

I found that webdriver.PhantomJS(service_args=['--cookies-file=/tmp/ph_cook.txt']) would add a given txt file at launch.

The problem is I do not know what format this txt file should be of. I tried using a map with key value pair, but no gain.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • Possible duplicate of [How can I use persisted cookies from a file using phantomjs](https://stackoverflow.com/questions/18739354/how-can-i-use-persisted-cookies-from-a-file-using-phantomjs) – Jacques Jul 24 '19 at 09:20

1 Answers1

0

The cookie file format is a Qt internal serialization format of cookies. If you need such a cookie file, follow those instructions:

  1. Create a PhantomJS script which sets the cookies that you need either using phantom.addCookie() or page.addCookie().
  2. Run the previously written script as

    $ phantomjs --cookies-file=cookies.txt script.js
    
  3. Use the generated cookies file in python.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222