First, let's just make an empty folder for our project to be inside.
So make dir.
Let's call it cookie off scraper.
Let's open it up in Visual Studio code and let's add some packages.
So here we have a totally empty directory opened up in Visual Studio code and let's add.
Request and request promise.
Now let's create a index.js file.
Index.js.
And let's start making some requests.
So const request.
Require.
Quest Promise.
And let's make an async function, let's call it main and let's call Main down here in the bottom.
So we can say const result request dot get and we need to get the first from page in order to get our
cookies set inside of request so that we can do the login request.
Because remember, if we don't have the cookies set, the logging is going to say 403 forbidden.
So let's go and say the site was called.
Intern Shalako.
And.
Let's go and say, Hey, wait here and let's go and also and get the login URL we found inside Chrome
Tools.
This post here.
Let's do that after and we say log in result await request post.
We have the URL here and we also need to pass in my username and password.
So we have email and my password here.
So we have a comma and then we can say form.
Equals email.
My email.
Password.
This one.
Okay, let's see how that fares.
Let's try Node.
Node Index.js.
And let's see what happens.
So we get a status code for all three.
Why do we get a full three?
Well, because we're not saving the cookies at all inside of request.
So let's try and say defaults.
And then have a curly brace and say char equals to true.
So now when we had set the char to true request is going to save the the cookies from request to request.
So that means we go and visit this page first.
Then request is going to set the cookies inside of its cookie jar.
That's what they call where they store all the cookies.
And then it's also going to have the same cookies set when we do the next request, in this case, the
post login request.
So we saved the cookies by using setting char to true.
Now let's try and run node index.js again.
And it looks like it's the same kind of response we're getting here.
So why could that be?
Well, I think it says something about CSR.
If the action you have requested is not allowed.
Now, if we take a look inside of our postman request, we can see there's also a CSR, a parameter
that's being sent in the post request body.
And if you don't have that set, well, it's going to return this response as well.
If you only have the email and password set.
It's going to return this response with four, four three forbidden.
This is not always the case for websites, websites.
In this case, they have some sort of csrf security.
So they test for that when they do when you do the post request.
It's not always the case.
Sometimes you could already be done with your login for a site if you just do this and enable the cookie
jar.
But for this site, they do want to have the c, r, SF or the.
The the.
I can't remember csrf token set.
Now, the next lecture, let's take a look at how we can pass in this csrf token to the post request.