F
F
frendri2019-11-04 17:30:01
Python
frendri, 2019-11-04 17:30:01

How to make a CookieJar in Python?

I have a working code in NodeJs, but I myself write in python:

const request = require('request');
const jar = request.jar();
const cloudscraper = require('cloudscraper').defaults({ jar });


jar.setCookie(request.cookie('session=dhLDWO2muzBCshW3XQ3UzRBPIoFhL734sL47TSnb'), "https://tradeback.io/");
jar.setCookie(request.cookie('remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=1142%7CjPt9bbgtNcF6YY5l3CSOIzZPFgov6b5hK2qdZRFxxDmsmfYSOTzKlsZf9JDQ%7C'), "https://tradeback.io/");

cloudscraper({
    url: "https://tradeback.io/api/comparison/load?lang=ru",
    qs: {
        "services":[{"name":"tm_market","updated":60}],"last_item_id":143376,
    },
})
.then((data) => {
    fs.writeFileSync('writeme.json', data);
});

I'm trying to convert this to python, but I can't figure out what request.cookie and .defaults({ jar }); mean.
How to convert it to Python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Chernyshev, 2019-11-05
@IvanBlacky

The logic of the script is as follows:
There is a site that you need to go to. The site is protected by cloudflare, which greatly complicates the task: there may be captchas, etc. Node.js has a module for working with cloudflare: cloudscraper, this script uses it. To work with the site, there are two cookies that must be passed along with the request. The module that is used for requests has a Jar -- storage for cookies. Two cookies are passed to this Jar, which are wrapped into objects needed for the module using the request.cookie(). The generated Jar is specified as the default Jar for requests that cloudscraper will send with .defaults({ jar });.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question