Using requests to handle cookies, hello, everyone, since the cookies topic is quite interesting because
everybody's interested about how his data is exchanged over the network.
I decided to make another video which will show you how you can hear the hand of cookies using requests.
So let's create a request to obtain some cookies.
So I will do a response.
Equal extra let's and Python more to write Python.
So let's right.
Let's first actually import your library and library
request and also import htp dot.
Cookie jar and let's right import.
The requests.
And then session equals requests that session.
OK, so here we are creating a second class.
In order to observe cookies from a website, but from which website would like to observe cookies,
so let's write the response.
Response, of course, request not to get.
HTP, GitHub, dot com.
That this request is not defined.
Yes, so let's do them your old Labrador's request so that I will two requests.
Yes, I think that's going to be a sentence.
That's it.
It took some time, but now it's good.
So let's run now print and then our response dog case.
And you can see that now we're able to print the cookies from GitHub dot com.
And you're already familiar with the cookies that we have from there, such as the logged in, which
is now said to know and the rest of the cookies, like G.H. says and so on.
So let's go back to the station.
So let's print session.
Not cookies, dot, get a dictionary, OK?
And then let's do a response.
Equals.
Session not get, and now you can see the first example, we can't print any type of cookies simply
because we don't pass any two main political parties.
But now let's right here in the briskets, HTP, GitHub dot com.
OK, and now let's do print's then session dot Corky's.
Don't get underscore dictionary, OK?
And I think that should be fine.
So you can see that this is another way that we can actually print all the cookies which some alternative
to the first one.
So you can either do it with the get method or with them get a dictionary from the session.
OK.
And so here we are using the same method in the same way as we used it in the requests I don't get.
But at this time we're using the class section in order to receive the cookies from the website.
So let's go now back to the ID, to the pie chart and let's create a new file in the file will be called
to Get Cookies.
So let's create the new Python file, actually.
And this file will be called Get Cookies, OK, and let's write it.
So now let's do it.
So this file is basically going to extract the cookies in there.
And there's a graphical user interface from GitHub, dot com or from any other domain.
So what I'm going to do is first I will do the Python directory.
So user.
We've been EMV Python three, that's it, and then there's two import requests let's remove this morning
here.
So syntax, that's it.
And let's try to function.
So Jeff, check HTP only.
OK, see, and that's right.
If H htp only.
In C.
Does underscore.
Rest.
Not Kei's return, true.
And then let's right else a return and in our case, ask to return this, call them cookies equal to
a list.
So we're creating a list from cookies and then I will do Eurail equal to.
H t t p h h GTP.
And give hope, dot com.
OK, and in response.
Response will be equal to requests don't get in the brickies euro.
OK, so here we're getting the worst ineke requests to the dot com and we're getting the response.
And now let's right for cocaine in response, not Corky's.
Let's print first name, comma, cookie, top name, and then let's print.
The value.
Como quoque, Movado, OK?
And finally, free cookies, cookies, dot.
Who keep that value and then, if not kookier, not secure.
So if the cookie is not secure or it doesn't have the secure code, who would like to cookie not secure
you cause.
Force and then out of Prince HTP, only coma, and then you can check HTP only and we'll check just
for Cauchy came because we're still in the for loop, so forever kookier.
We're going to check if it is HTP only and analyst right here and actually backslash.
And so we go to a new role and that's to the base.
Let's save this cold and let's go now to the terminal where we can run it.
So I'll exit the python mode and I'll write aways so you can see that the file get actually I wrote
and got to kiss me because I'm filming for already about one hour and a half.
But let's actually run the file and see if everything is correct.
So Python got cookies and we have some error here.
Let's go back to the code and try to fix it.
So here is the old guys.
Here's cookies instead of Cookie.
And this is why we've got this cookie system defined.
The cost was actually not defined, but now it will be fine.
Let's save it and I will run the code again.
So now you can see that we're getting all the information that were requested.
So for this cookie, we get the name we just logged in in a very nice graphics so you can easily distinguish
it.
Then you get the cookie volume, which is now and then you get if it is HTP only, which is here, false.
So you can see that here.
And after that you can see the actual cookie and again, the HTP only that is equal to force, which
is exactly what you wrote in the code.
So let's right here print set and cookies.
So if I run the file again, you can see the difference that we see more than one cookie at this time.
So here we see the set of all cookies and on the top we see the cookie with the information that we
desired.
So that said, guys, thank you very much for watching.
This was actually quite an interesting lecture.