Working with cookies, hello, everyone.
Today we're actually going to be working with cookies and I will show some quite cool stuff that you
can do just from the terminal.
And in the end, we're going to create a Python script that will run cookies as well.
But now let's take Python and let's write some called here.
So first I import your library and then let's create the cookie processor, Ferrite Cookie.
Processer and this will be equal to Eurorail library dot request.
Dr. H.T..
Being quoque.
Professor.
OK, so now we can see that the Euro Labrecque is not the north from which request let's solid request.
OK, and it's from the same court again, and now it's accepted.
So that's good.
So let let's know right from HTP Dot.
Cookie jar.
Import cookie jar.
OK, so if you don't know what cookie jar is, this is the way that you can send your own cookies by
creating cookie jar object of the cookie library.
And this will be as a parameter, the cookie process or initialized.
So this is why we're going to use diskless here.
So here we just need to create object in the cookie jar class.
Let's do that while the cookie jar equals.
Cookie jar.
OK, so now we have this object from the cookie jar class and let's try it now.
Cookie underscore processer equals hero library dot request dot htp p.
Cookie processer, and then I'll write the cookie jar inside the cookie jar.
That's it.
And then let's write Eyeopener or what who opening the cookie, who do call to your L library request.
OK, don't built opener and I write here, Kookie.
Processor, and that's it, and the final line you need to do is you RL Library, DOT request, don't
install opener and write opener.
That's it.
And we can use the opener so we can make the HTP request.
So let's write open.
They're not open in here.
All right.
Let's say h h t p double double double double digit hope dot com.
OK, let's see what will happen now.
So we wait a bit and you can see that we've got the HTP response.
Kalayaan so successfully completed the dissection to open the GitHub page, so let's see the cookies
that has been sent.
So if I write the letter and the cookie jar, let's see if we have any items in that jar so you can
see that we actually have tried them.
So we receive through cookies from the GitHub dot com.
So since we have these cookies now in the future, every time when we make further requests to this
website, the HTP cookie processor will use the cookie jar to check if there are any cookies currently
existing.
And if they are, the program will automatically use them in order to personalize the use of this website
by us.
So we now know that we have three cookies, but let's see what actually those cookies are.
So I write Cookie Cookies, Equal List and I'll write a cookie jar.
OK, so here will create the list with all the cookies that we have in the cookie jar and then we would
like to display this list or simply write cookies so we can see now we have plenty of information.
But there's one specific, very important information in there is the cookie information.
So if you see here, here is the name of the first cookie, which is called Long in the Flour Cookie,
which is called G.H. says, and we should have a third cookie.
Let's see where this if we can find it.
That'd be great, actually.
And yes, actually, I missed the first one, but it was here in the beginning.
It's called octal.
So these are all the cookies.
We can also see a lot of information related to the board.
And basically you can see how much information we're getting per cookie.
Quite a lot, isn't it?
So this is the second and this is the third.
So you can actually see that in some of the cookies.
For example, this one here's the HTP on this block, which means that this cookie.
So in that case, Cookie cannot be assessed only from a strategic plan, but also from all other clients.
You know, but if this is true, this means that the cookie can be assessed only from the HTP protocol.
So usually it's good that this cookie it's equal to.
Yes, but not too long, because if the HTP only is on, this will prevent the cookie from the cross-eyed
scripting attacks.
And that important feature is a secure fluck, which is also very important for the security of the
cookie.
And you can see that here in all the cases, the secure equals the true.
So this means that even though the HTP only second to none, this school is more secure and you shouldn't
be worried that your data is, for example, more vulnerable.
So let's right now one script in order to extract cookie information.
So let's create a new file.
And they were right, OK, not to file, but python file.
We need so vital file and.
All right, Cookie.
OK.
So let's right here in Fort HTP, not cookie jar, and then after this, let's import.
You RL library, they remove the warnings here and then that's right, Purell or this will be the euro
that will be using will be equal to HTP is.
You help dot com.
Let me get closer.
So let's try to function now in this function were extracted the quickest information, so I'll name
it extract.
So let's right here kookie underscore J4 cookie jar equals to HTP.
Not cookie jar, not cookie jar.
OK, so this is an object.
Hookergate is an object from the classic cookie jar and let's create an opener, OK, which will be
equal to Eurorail library dot request dot built underscore open and actually let's import the OCU the
library dot request.
OK, so we can recognize this.
And now if I write a thought then we should see the built opener.
That's right.
And inside I'll write you a real library note request.
Dot htp cookie processer.
That's it.
And then Cookie underscored G.
So now we're created our opener and then let's write.
Response equals open or not open.
And then the euro that we used that said.
And then let's create four.
So here we're actually going to print the data.
So for Cookie.
In.
Cookie jar.
Prince, That's right, Cookie and then percent is.
Then again, Percent.
S and the S is going to actually be OK.
This particular you name.
And cookie dough Movado actually had to remove the colon because it's incorrect.
And also here I am, is that the column?
OK, so now everything is fine.
So let's now if this loop is exited, let's print.
So print.
Heather's.
Yes, and that's right.
RESP don't.
Heather.
OK, so let me save that, as you can see, the courts accept that and let's go to a terminal run at.
And see what happens, but actually wait, I've got to go to the final statement that we run next to
the function, so I will write you name equals.
Maine, OK.
And we'll run the exact function like this.
OK, so let's go now to the terminal.
I will exit the python mode and left right airways so we can see the cookie files.
Right.
Python cookie dough your way.
And let's see.
So we're getting nearer here so I can see there here, guys, I wrote, I hope instead of get help,
let's fix it up and let's try to run the code again.
So we're still getting in there.
Let's see what this.
So here I forgot.
What's the break?
It's up to the cookie jar, obviously, because it's a function.
Let's save it now and let's try it from the terminal to see if it's going to work.
And you can see now that everything works.
So here's how you can obtain cookies from a website directly.
So you can see here the set cook cold, OK?
And basically the same cookies that we sold previously are now displayed.
But just the cookies here from this website, GitHub dot com and are displayed by a script, but not
by simply writing commands in Python.
So when you run the script to GitHub dot com, you're going to get all this information and this account
for every website.
For example, if you do YouTube dot com, you're also going to be able to see the cookies from this
website as well.
So if I run again, python cookie dough white, you will see that here.
Now the host is different, the domain is different.
And you can see the cookies that are tracking my computer from YouTube dot com.
So here's one of them here, a second one.
Then there is a third one, the set cookies.
So we have visitor info, Life, Domain Express and so on.
And you can see that there about, OK, I think they are open more than three.
So they're actually quite a lot of cookies, as you can see here.
So it gives a signal that while the visitor info life, we have all the headers here and then all the
cookies.
So whatever you want to check, if our website is tracking your data, for example, you might want
to remove cookies, check the script and simply update the domain.
You can even make this quick, even nicer by allowing the user to write a domain that he desires, for
example, urea exports to imports.
And then I will write here.
Right, a eurorail, and let's save that.
So when you run the cold now, now you're asked to write a Eurail.
So, for example, I will write let's say
h t.
T p.
Google dot com.
OK.
And after I press enter, I will be able to see all the cookies that are tracking from Google.
So if you create the quote in that way, every time that you run the code, you will be able to write
the website and check the cookies that are currently on your computer from that website by sending the
request and the receiving the response.
So this was everything else I want to share with you about cookies is very important to know them,
because the data security and information exchange between you and the other servers and the network
is quite important.
That said, thank you very much for watching and I'll see you in the next video.