A
A
Alexander2020-09-07 19:58:39
PHP
Alexander, 2020-09-07 19:58:39

How to correctly generate a cookieJar file in js so that later it can be fed to CURL?

you need to make access to the personal account of one service, they don’t have an apish and there is protection from bots
. As a result, you have to pervert. I
log in and get a session using Puppeteer.
And you already need to pull the data using curl, using the data of the received

session .

let cookieJar = await cookies.map(row => {
        let cookieRow = []
        cookieRow.push(row['domain'])   // the domain name
        cookieRow.push('FALSE')         // include subdomains
        cookieRow.push(row['path'])     // path
        cookieRow.push(row['secure'])   // send/receive over HTTPS only
        cookieRow.push(row['expires'])  //
        cookieRow.push(row['name'])     // name of the cookie
        cookieRow.push(row['value'])    // value of the cookie
        return cookieRow.join('\t');
    }).join('\n')

resulting in a file of this format
127.0.0.1	FALSE	/	false	-1	PHPSESSID	fd435as2kcpkc3ovah88022e1j

when I use it in Curl it doesn't help
$ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
//        curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=fd435as2kcpkc3ovah88022e1j;'); // это работает
        curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookieJarFile); // при попытке прочитать из файла - не работает

What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2020-09-08
@alexmixaylov

1. replace CURLOPT_COOKIEFILE with CURLOPT_COOKIEJAR and see how cookies are saved
2. why the heck do you need to form this format? generate CURLOPT_COOKIE from any format

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question