E
E
Evgen Trezvykh2014-01-21 09:58:06
Qt
Evgen Trezvykh, 2014-01-21 09:58:06

How to convert cookie to QList format?

You need to convert the cookie to the QList < QNetworkCookie > format. I tried to pick up the structure of saving through regular expressions, but without result. Now I'm trying to save them through PhantomJS itself, I pass them to the script via the command line parameter in the form of JSON:

var needCookies = JSON.parse(require('system').args[1]);
    for (key in needCookies) {
        console.log(phantom.addCookie(needCookies[key]));
    }
    console.log(JSON.stringify(phantom.cookies, null, 2));
    phantom.exit();

After the session is closed, Phantom does not store these cookies in a file dedicated to it via the "--cookies-file" parameter
Request example:
C:\phantomjs\phantomjs.exe --cookies-file=C:\server\www\lib3\get_content\_parser_lib\cCookie\cookies\testCookies-phantomjs.cookie --ignore-ssl-errors=true --load-images=true --local-storage-path=C:\server\www\lib3\get_content\_parser_lib\cPhantomJS\storage --output-encoding=utf-8 --local-to-remote-url-access=true 'C:\server\www\lib3\get_content\_parser_lib\cPhantomJS\script\addCookie.js' '^[^{^"name^":^"PHPSESSID^",^"value^":^"asdf123465^",^"domain^":^".test1.ru^",^"path^":^"^\/^",^"expires^":^"Wed, 22-Jan-14 05:58:58 GMT^",^"httponly^":false,^"secure^":false^},^{^"name^":^"testName^",^"value^":^"testValue^",^"domain^":^".test1.ru^",^"path^":^"^\/^",^"expires^":^"Wed, 22-Jan-14 05:58:58 GMT^",^"httponly^":false,^"secure^":false^}^]'

Example cookie data:
[General]
cookies="@Variant(\0\0\0\x7f\0\0\0\x16QList<QNetworkCookie>\0\0\0\0\x1\0\0\0\x4\0\0\0\x61logged_in=no; secure; HttpOnly; expires=Sat, 21-Jan-2034 01:18:06 GMT; domain=.github.com; path=/\0\0\0w__utma=1.138296252.1390267083.1390267083.1390267083.1; expires=Thu, 21-Jan-2016 01:18:02 GMT; domain=github.com; path=/\0\0\0Z__utmb=1.1.10.1390267083; expires=Tue, 21-Jan-2014 01:48:02 GMT; domain=github.com; path=/\0\0\0\x87__utmz=1.1390267083.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); expires=Tue, 22-Jul-2014 13:18:02 GMT; domain=github.com; path=/)"

Tried with a dummy file to render and set Cookies, but phantom doesn't send a cookie if the domain doesn't match. Are there any craftsmen here who have worked a lot with PhantomJS and know how to solve this problem? I'm already exhausted, the third day I'm doing it.
PS
+ The fact that phantomJS uses Qt serialized data to store cookies, I know if you know how to convert to this format, I would be grateful for advice.
+ I re-read the entire manual (on github), I did not find anything about this topic. If you are more observant than me, let me read the link.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question