1 00:00:04,820 --> 00:00:07,810 Working with cookies, hello, everyone. 2 00:00:07,820 --> 00:00:12,920 Today we're actually going to be working with cookies and I will show some quite cool stuff that you 3 00:00:12,920 --> 00:00:15,310 can do just from the terminal. 4 00:00:16,070 --> 00:00:20,650 And in the end, we're going to create a Python script that will run cookies as well. 5 00:00:20,810 --> 00:00:25,590 But now let's take Python and let's write some called here. 6 00:00:25,880 --> 00:00:36,650 So first I import your library and then let's create the cookie processor, Ferrite Cookie. 7 00:00:39,060 --> 00:00:46,530 Processer and this will be equal to Eurorail library dot request. 8 00:00:48,740 --> 00:00:50,420 Dr. H.T.. 9 00:00:52,030 --> 00:00:54,220 Being quoque. 10 00:00:56,730 --> 00:00:57,310 Professor. 11 00:00:57,900 --> 00:01:04,860 OK, so now we can see that the Euro Labrecque is not the north from which request let's solid request. 12 00:01:06,750 --> 00:01:10,720 OK, and it's from the same court again, and now it's accepted. 13 00:01:11,190 --> 00:01:11,960 So that's good. 14 00:01:12,450 --> 00:01:18,600 So let let's know right from HTP Dot. 15 00:01:20,450 --> 00:01:22,030 Cookie jar. 16 00:01:23,900 --> 00:01:26,930 Import cookie jar. 17 00:01:27,230 --> 00:01:35,600 OK, so if you don't know what cookie jar is, this is the way that you can send your own cookies by 18 00:01:35,600 --> 00:01:41,110 creating cookie jar object of the cookie library. 19 00:01:41,900 --> 00:01:48,620 And this will be as a parameter, the cookie process or initialized. 20 00:01:49,760 --> 00:01:53,700 So this is why we're going to use diskless here. 21 00:01:54,200 --> 00:01:58,410 So here we just need to create object in the cookie jar class. 22 00:01:58,700 --> 00:02:04,670 Let's do that while the cookie jar equals. 23 00:02:07,180 --> 00:02:07,930 Cookie jar. 24 00:02:08,150 --> 00:02:14,620 OK, so now we have this object from the cookie jar class and let's try it now. 25 00:02:15,850 --> 00:02:28,090 Cookie underscore processer equals hero library dot request dot htp p. 26 00:02:30,090 --> 00:02:36,820 Cookie processer, and then I'll write the cookie jar inside the cookie jar. 27 00:02:37,140 --> 00:02:37,740 That's it. 28 00:02:39,130 --> 00:02:51,170 And then let's write Eyeopener or what who opening the cookie, who do call to your L library request. 29 00:02:52,150 --> 00:02:59,080 OK, don't built opener and I write here, Kookie. 30 00:03:00,800 --> 00:03:13,820 Processor, and that's it, and the final line you need to do is you RL Library, DOT request, don't 31 00:03:14,420 --> 00:03:17,880 install opener and write opener. 32 00:03:18,920 --> 00:03:19,630 That's it. 33 00:03:20,120 --> 00:03:24,550 And we can use the opener so we can make the HTP request. 34 00:03:24,980 --> 00:03:27,050 So let's write open. 35 00:03:27,050 --> 00:03:32,320 They're not open in here. 36 00:03:32,330 --> 00:03:32,960 All right. 37 00:03:33,560 --> 00:03:41,960 Let's say h h t p double double double double digit hope dot com. 38 00:03:42,930 --> 00:03:45,810 OK, let's see what will happen now. 39 00:03:45,890 --> 00:03:51,020 So we wait a bit and you can see that we've got the HTP response. 40 00:03:51,020 --> 00:04:00,140 Kalayaan so successfully completed the dissection to open the GitHub page, so let's see the cookies 41 00:04:00,140 --> 00:04:01,370 that has been sent. 42 00:04:01,790 --> 00:04:10,460 So if I write the letter and the cookie jar, let's see if we have any items in that jar so you can 43 00:04:10,460 --> 00:04:12,020 see that we actually have tried them. 44 00:04:12,020 --> 00:04:16,190 So we receive through cookies from the GitHub dot com. 45 00:04:16,700 --> 00:04:22,460 So since we have these cookies now in the future, every time when we make further requests to this 46 00:04:22,460 --> 00:04:32,300 website, the HTP cookie processor will use the cookie jar to check if there are any cookies currently 47 00:04:32,300 --> 00:04:32,930 existing. 48 00:04:33,200 --> 00:04:41,330 And if they are, the program will automatically use them in order to personalize the use of this website 49 00:04:41,330 --> 00:04:41,850 by us. 50 00:04:42,170 --> 00:04:47,770 So we now know that we have three cookies, but let's see what actually those cookies are. 51 00:04:47,780 --> 00:04:59,000 So I write Cookie Cookies, Equal List and I'll write a cookie jar. 52 00:04:59,240 --> 00:05:06,230 OK, so here will create the list with all the cookies that we have in the cookie jar and then we would 53 00:05:06,230 --> 00:05:11,990 like to display this list or simply write cookies so we can see now we have plenty of information. 54 00:05:12,260 --> 00:05:18,310 But there's one specific, very important information in there is the cookie information. 55 00:05:18,740 --> 00:05:26,990 So if you see here, here is the name of the first cookie, which is called Long in the Flour Cookie, 56 00:05:27,080 --> 00:05:34,500 which is called G.H. says, and we should have a third cookie. 57 00:05:34,520 --> 00:05:36,980 Let's see where this if we can find it. 58 00:05:36,980 --> 00:05:38,070 That'd be great, actually. 59 00:05:38,690 --> 00:05:43,370 And yes, actually, I missed the first one, but it was here in the beginning. 60 00:05:43,370 --> 00:05:44,590 It's called octal. 61 00:05:45,620 --> 00:05:47,030 So these are all the cookies. 62 00:05:47,660 --> 00:05:52,190 We can also see a lot of information related to the board. 63 00:05:52,190 --> 00:05:57,800 And basically you can see how much information we're getting per cookie. 64 00:05:58,700 --> 00:06:00,040 Quite a lot, isn't it? 65 00:06:00,110 --> 00:06:03,610 So this is the second and this is the third. 66 00:06:04,610 --> 00:06:07,640 So you can actually see that in some of the cookies. 67 00:06:07,640 --> 00:06:13,640 For example, this one here's the HTP on this block, which means that this cookie. 68 00:06:14,780 --> 00:06:21,230 So in that case, Cookie cannot be assessed only from a strategic plan, but also from all other clients. 69 00:06:21,620 --> 00:06:29,510 You know, but if this is true, this means that the cookie can be assessed only from the HTP protocol. 70 00:06:29,870 --> 00:06:34,790 So usually it's good that this cookie it's equal to. 71 00:06:34,790 --> 00:06:43,240 Yes, but not too long, because if the HTP only is on, this will prevent the cookie from the cross-eyed 72 00:06:43,250 --> 00:06:44,390 scripting attacks. 73 00:06:45,000 --> 00:06:51,320 And that important feature is a secure fluck, which is also very important for the security of the 74 00:06:51,320 --> 00:06:51,760 cookie. 75 00:06:51,980 --> 00:06:57,350 And you can see that here in all the cases, the secure equals the true. 76 00:06:57,440 --> 00:07:05,720 So this means that even though the HTP only second to none, this school is more secure and you shouldn't 77 00:07:05,720 --> 00:07:09,290 be worried that your data is, for example, more vulnerable. 78 00:07:09,800 --> 00:07:14,900 So let's right now one script in order to extract cookie information. 79 00:07:15,320 --> 00:07:17,360 So let's create a new file. 80 00:07:18,260 --> 00:07:21,540 And they were right, OK, not to file, but python file. 81 00:07:21,590 --> 00:07:24,430 We need so vital file and. 82 00:07:24,440 --> 00:07:25,980 All right, Cookie. 83 00:07:26,750 --> 00:07:27,170 OK. 84 00:07:29,080 --> 00:07:42,850 So let's right here in Fort HTP, not cookie jar, and then after this, let's import. 85 00:07:44,770 --> 00:07:54,820 You RL library, they remove the warnings here and then that's right, Purell or this will be the euro 86 00:07:54,820 --> 00:08:01,840 that will be using will be equal to HTP is. 87 00:08:03,540 --> 00:08:05,780 You help dot com. 88 00:08:07,680 --> 00:08:08,910 Let me get closer. 89 00:08:10,110 --> 00:08:17,090 So let's try to function now in this function were extracted the quickest information, so I'll name 90 00:08:17,100 --> 00:08:19,400 it extract. 91 00:08:19,950 --> 00:08:27,360 So let's right here kookie underscore J4 cookie jar equals to HTP. 92 00:08:28,260 --> 00:08:33,630 Not cookie jar, not cookie jar. 93 00:08:33,750 --> 00:08:37,490 OK, so this is an object. 94 00:08:37,500 --> 00:08:45,210 Hookergate is an object from the classic cookie jar and let's create an opener, OK, which will be 95 00:08:45,210 --> 00:09:03,170 equal to Eurorail library dot request dot built underscore open and actually let's import the OCU the 96 00:09:03,300 --> 00:09:06,060 library dot request. 97 00:09:06,150 --> 00:09:08,490 OK, so we can recognize this. 98 00:09:08,490 --> 00:09:14,600 And now if I write a thought then we should see the built opener. 99 00:09:14,750 --> 00:09:15,380 That's right. 100 00:09:15,600 --> 00:09:21,690 And inside I'll write you a real library note request. 101 00:09:22,620 --> 00:09:25,910 Dot htp cookie processer. 102 00:09:26,370 --> 00:09:27,030 That's it. 103 00:09:27,660 --> 00:09:30,430 And then Cookie underscored G. 104 00:09:30,930 --> 00:09:34,360 So now we're created our opener and then let's write. 105 00:09:34,380 --> 00:09:41,430 Response equals open or not open. 106 00:09:42,120 --> 00:09:45,240 And then the euro that we used that said. 107 00:09:47,000 --> 00:09:48,420 And then let's create four. 108 00:09:49,250 --> 00:09:51,660 So here we're actually going to print the data. 109 00:09:51,740 --> 00:09:53,870 So for Cookie. 110 00:09:56,200 --> 00:09:56,620 In. 111 00:09:58,430 --> 00:09:59,530 Cookie jar. 112 00:10:01,630 --> 00:10:07,810 Prince, That's right, Cookie and then percent is. 113 00:10:10,240 --> 00:10:11,720 Then again, Percent. 114 00:10:11,750 --> 00:10:18,850 S and the S is going to actually be OK. 115 00:10:18,890 --> 00:10:21,470 This particular you name. 116 00:10:24,150 --> 00:10:31,620 And cookie dough Movado actually had to remove the colon because it's incorrect. 117 00:10:32,860 --> 00:10:35,360 And also here I am, is that the column? 118 00:10:36,130 --> 00:10:38,060 OK, so now everything is fine. 119 00:10:39,460 --> 00:10:44,770 So let's now if this loop is exited, let's print. 120 00:10:45,670 --> 00:10:46,570 So print. 121 00:10:48,470 --> 00:10:49,310 Heather's. 122 00:10:52,320 --> 00:10:56,000 Yes, and that's right. 123 00:10:58,330 --> 00:10:59,880 RESP don't. 124 00:11:03,360 --> 00:11:03,840 Heather. 125 00:11:06,570 --> 00:11:14,130 OK, so let me save that, as you can see, the courts accept that and let's go to a terminal run at. 126 00:11:17,430 --> 00:11:24,600 And see what happens, but actually wait, I've got to go to the final statement that we run next to 127 00:11:24,600 --> 00:11:32,310 the function, so I will write you name equals. 128 00:11:34,970 --> 00:11:36,810 Maine, OK. 129 00:11:39,690 --> 00:11:43,050 And we'll run the exact function like this. 130 00:11:43,620 --> 00:11:45,530 OK, so let's go now to the terminal. 131 00:11:45,900 --> 00:11:53,370 I will exit the python mode and left right airways so we can see the cookie files. 132 00:11:53,550 --> 00:11:53,850 Right. 133 00:11:54,390 --> 00:11:58,040 Python cookie dough your way. 134 00:11:58,860 --> 00:12:00,020 And let's see. 135 00:12:00,420 --> 00:12:08,640 So we're getting nearer here so I can see there here, guys, I wrote, I hope instead of get help, 136 00:12:08,730 --> 00:12:12,060 let's fix it up and let's try to run the code again. 137 00:12:12,780 --> 00:12:14,080 So we're still getting in there. 138 00:12:14,100 --> 00:12:15,080 Let's see what this. 139 00:12:15,990 --> 00:12:17,480 So here I forgot. 140 00:12:17,490 --> 00:12:19,070 What's the break? 141 00:12:19,100 --> 00:12:22,340 It's up to the cookie jar, obviously, because it's a function. 142 00:12:23,040 --> 00:12:27,630 Let's save it now and let's try it from the terminal to see if it's going to work. 143 00:12:27,870 --> 00:12:30,360 And you can see now that everything works. 144 00:12:30,780 --> 00:12:34,920 So here's how you can obtain cookies from a website directly. 145 00:12:35,550 --> 00:12:40,220 So you can see here the set cook cold, OK? 146 00:12:40,590 --> 00:12:44,880 And basically the same cookies that we sold previously are now displayed. 147 00:12:45,180 --> 00:12:52,260 But just the cookies here from this website, GitHub dot com and are displayed by a script, but not 148 00:12:52,260 --> 00:12:54,960 by simply writing commands in Python. 149 00:12:54,990 --> 00:13:01,710 So when you run the script to GitHub dot com, you're going to get all this information and this account 150 00:13:01,710 --> 00:13:02,570 for every website. 151 00:13:02,940 --> 00:13:11,280 For example, if you do YouTube dot com, you're also going to be able to see the cookies from this 152 00:13:11,280 --> 00:13:12,220 website as well. 153 00:13:12,600 --> 00:13:18,110 So if I run again, python cookie dough white, you will see that here. 154 00:13:18,150 --> 00:13:20,370 Now the host is different, the domain is different. 155 00:13:20,580 --> 00:13:24,940 And you can see the cookies that are tracking my computer from YouTube dot com. 156 00:13:25,080 --> 00:13:28,760 So here's one of them here, a second one. 157 00:13:29,700 --> 00:13:31,850 Then there is a third one, the set cookies. 158 00:13:31,850 --> 00:13:38,220 So we have visitor info, Life, Domain Express and so on. 159 00:13:39,150 --> 00:13:44,600 And you can see that there about, OK, I think they are open more than three. 160 00:13:44,610 --> 00:13:48,640 So they're actually quite a lot of cookies, as you can see here. 161 00:13:49,560 --> 00:13:58,770 So it gives a signal that while the visitor info life, we have all the headers here and then all the 162 00:13:58,770 --> 00:13:59,300 cookies. 163 00:13:59,580 --> 00:14:05,340 So whatever you want to check, if our website is tracking your data, for example, you might want 164 00:14:05,340 --> 00:14:12,480 to remove cookies, check the script and simply update the domain. 165 00:14:13,080 --> 00:14:20,430 You can even make this quick, even nicer by allowing the user to write a domain that he desires, for 166 00:14:20,430 --> 00:14:23,040 example, urea exports to imports. 167 00:14:23,880 --> 00:14:25,380 And then I will write here. 168 00:14:26,920 --> 00:14:32,480 Right, a eurorail, and let's save that. 169 00:14:33,040 --> 00:14:36,990 So when you run the cold now, now you're asked to write a Eurail. 170 00:14:37,300 --> 00:14:40,270 So, for example, I will write let's say 171 00:14:42,970 --> 00:14:45,790 h t. 172 00:14:45,790 --> 00:14:46,600 T p. 173 00:14:49,090 --> 00:14:50,530 Google dot com. 174 00:14:51,550 --> 00:14:51,950 OK. 175 00:14:52,240 --> 00:14:59,200 And after I press enter, I will be able to see all the cookies that are tracking from Google. 176 00:14:59,680 --> 00:15:05,270 So if you create the quote in that way, every time that you run the code, you will be able to write 177 00:15:05,280 --> 00:15:10,900 the website and check the cookies that are currently on your computer from that website by sending the 178 00:15:10,900 --> 00:15:12,790 request and the receiving the response. 179 00:15:13,240 --> 00:15:17,830 So this was everything else I want to share with you about cookies is very important to know them, 180 00:15:17,830 --> 00:15:24,190 because the data security and information exchange between you and the other servers and the network 181 00:15:24,190 --> 00:15:25,240 is quite important. 182 00:15:25,570 --> 00:15:29,280 That said, thank you very much for watching and I'll see you in the next video.