1 00:00:04,670 --> 00:00:08,930 Consuming co-op services with your library. 2 00:00:09,110 --> 00:00:09,780 Hi, everyone. 3 00:00:09,800 --> 00:00:10,970 Welcome back to the course. 4 00:00:11,370 --> 00:00:15,620 Today, we're going to talk in the section about programming in the Web. 5 00:00:15,920 --> 00:00:23,540 Using the HTP protocol, you learn how to make requests on the Web and retrieve Web resources. 6 00:00:24,320 --> 00:00:27,980 You be trained here, plenty of example requests. 7 00:00:28,310 --> 00:00:35,730 You will be using the euro library and you'll be working with different forms and cookies over the web. 8 00:00:35,900 --> 00:00:43,760 So in this section, you're basically going to gain a strong understanding about the Euro library package. 9 00:00:44,060 --> 00:00:47,960 You understand how to use the request package as well. 10 00:00:48,260 --> 00:00:55,960 You learn how to handle forms using the euro library and the requests with Python three point seven. 11 00:00:55,970 --> 00:01:00,470 And actually, we're going to use some of the newest Python version, which is going to be three point 12 00:01:00,470 --> 00:01:00,820 nine. 13 00:01:01,190 --> 00:01:04,490 You will learn how to handle cookies with the same packages. 14 00:01:04,790 --> 00:01:11,930 And finally, we're going to talk about the HTP and the HTP is authentication medal's. 15 00:01:12,230 --> 00:01:16,650 So let's go to our terminal and let's get started. 16 00:01:17,180 --> 00:01:20,490 Now, let's pull up the terminal and here's our terminal. 17 00:01:20,510 --> 00:01:23,610 Let me actually make it a little bit bigger so you can see better. 18 00:01:24,590 --> 00:01:32,890 So here's our terminal guys, and we're actually going to run some files in order for us to start to 19 00:01:32,930 --> 00:01:35,460 think requests and cookies. 20 00:01:36,170 --> 00:01:42,950 So, as I said, the first four stores that are actually going to use the library and basically the 21 00:01:43,700 --> 00:01:52,730 library allows you to access any resource that is published on the network, such as files, pictures, 22 00:01:53,450 --> 00:01:55,990 directories and so on. 23 00:01:56,000 --> 00:02:04,700 It's a very powerful tool and it uses the protocol HTP in order to assess these files over the web. 24 00:02:05,210 --> 00:02:08,510 Now, how important legible to python molds? 25 00:02:09,990 --> 00:02:13,020 Here we're are, Baltimore, and you can simply import. 26 00:02:14,400 --> 00:02:19,340 You are a liberal, OK, and you can see that we don't get there. 27 00:02:19,680 --> 00:02:21,300 So this is the way you can import it. 28 00:02:21,450 --> 00:02:27,210 And also if you get there or here, this means that the liberals probably not installed in your computer 29 00:02:27,220 --> 00:02:38,640 so you can write them pipe install you R.L. Library, and if it is not installed, it will immediately 30 00:02:38,640 --> 00:02:39,810 install your computer. 31 00:02:40,630 --> 00:02:43,670 But us here is a library that is installed. 32 00:02:43,680 --> 00:02:48,200 Now, you can see that I'm getting the message that I don't need to install it. 33 00:02:48,720 --> 00:02:50,540 So let's go to Python Molt again. 34 00:02:51,180 --> 00:02:58,770 So when we're talking about the library, there are basically four functions that are covering this 35 00:02:58,770 --> 00:02:59,260 library. 36 00:02:59,460 --> 00:03:07,170 The first one is the request which simply opens and the reads are Eurail or some other is over the Web. 37 00:03:07,530 --> 00:03:11,940 Then we have the error which contains the errors generated. 38 00:03:11,940 --> 00:03:20,760 When you making the request, then you have the past two or cold parts, which basically converts the 39 00:03:20,760 --> 00:03:23,520 euro into the readable information for you. 40 00:03:23,820 --> 00:03:25,170 And finally, do we have. 41 00:03:26,440 --> 00:03:27,910 The report. 42 00:03:29,710 --> 00:03:38,080 Paris, which basically covers the route, takes files and as a matter of fact, if you go to this website, 43 00:03:38,080 --> 00:03:46,930 Dr. Dot Python dot org, and if you search for the euro library DOT request, you can find all the documentation 44 00:03:46,930 --> 00:03:53,600 for the Euro Library DOT request and actually find all the functions related to it. 45 00:03:53,890 --> 00:03:59,230 So whilst we complete this section, if you want to do some additional functions, this is a great place 46 00:03:59,230 --> 00:04:03,760 to go and see what each function is doing and simply use it for your needs. 47 00:04:04,060 --> 00:04:09,940 This here is the euro of the library, so you can simply type it in your browser and you will gain access 48 00:04:09,940 --> 00:04:10,300 to it. 49 00:04:10,870 --> 00:04:15,700 For example, if I search here for you are now. 50 00:04:17,590 --> 00:04:26,350 Open, we're getting here the open function, and you can read the documentation for it, so here Dysfunction 51 00:04:26,710 --> 00:04:35,230 Open is simply creating a file similar to a text file that is extracted from a Eurail. 52 00:04:35,470 --> 00:04:42,790 So what the system does when you use this common here, it basically converts or reads the euro and 53 00:04:42,790 --> 00:04:44,350 convert it to a file. 54 00:04:44,590 --> 00:04:52,060 And this object has many different methods, such as rethread line read lines, clothes and so on, 55 00:04:52,270 --> 00:04:53,320 wants to create the file. 56 00:04:53,330 --> 00:04:56,650 You can basically manipulate it in a way you like. 57 00:04:57,220 --> 00:04:59,300 For example, let's right here. 58 00:04:59,320 --> 00:05:02,660 So now we're in a python mode and let me show you how we go there. 59 00:05:03,700 --> 00:05:08,890 So let's write Python and once were taken Python code. 60 00:05:08,890 --> 00:05:11,650 You can separate from U. 61 00:05:11,650 --> 00:05:17,230 RL Library DOT request. 62 00:05:18,850 --> 00:05:25,900 So request import, you are open. 63 00:05:27,740 --> 00:05:35,330 OK, so now we imported the euro open option from the euro, Labrador's request, and then if we're 64 00:05:35,330 --> 00:05:39,260 right, the response, so this is going to be a variable. 65 00:05:39,560 --> 00:05:43,360 So we're suppose equal to the euro open. 66 00:05:44,180 --> 00:05:50,280 OK, and let's type some example address on the Web that we would like to explore. 67 00:05:50,300 --> 00:05:55,140 For example, let's up one of the most famous websites, a YouTube dot com. 68 00:05:55,490 --> 00:05:57,950 So if we do H.T. be. 69 00:05:59,730 --> 00:06:04,910 Slash, slash, w w w dot, YouTube and dot com. 70 00:06:06,460 --> 00:06:12,850 OK, and if we're on that, OK, we're getting nearer here, let's see where it is. 71 00:06:14,150 --> 00:06:21,170 Yes, here I misspelt with the euro open, so let me pick it up and now I can see that we're not getting 72 00:06:21,170 --> 00:06:26,780 on there, but we're also doing this painting because we need to call the variable that we just created, 73 00:06:27,020 --> 00:06:28,360 which is called response. 74 00:06:29,120 --> 00:06:38,330 So if I write a response here, you can see that we already called the HTP don't claim HTP response 75 00:06:38,330 --> 00:06:40,180 and we have that resoled object. 76 00:06:40,730 --> 00:06:45,560 So this means that we already passed the data from YouTube to that object. 77 00:06:45,830 --> 00:06:53,360 And if we're right, for example, now response dot red line. 78 00:06:56,580 --> 00:07:03,600 You can see that we can perfectly read the data that we received from YouTube, so by Ridgeland. 79 00:07:06,910 --> 00:07:15,820 You know, we usually receive an HTML file once we get the YouTube dot com and HTML file goes through 80 00:07:15,820 --> 00:07:16,820 the response object. 81 00:07:17,140 --> 00:07:23,320 So here by writing Crillon, we simply get the header of this HTML file. 82 00:07:23,480 --> 00:07:30,880 OK, I mean, the way that this file was written here, it's not very understandable because there's 83 00:07:30,880 --> 00:07:32,160 just written in the same line. 84 00:07:32,560 --> 00:07:40,750 But if you put it in the correct HTML converter, you'll see it very well with a different annotation 85 00:07:40,750 --> 00:07:41,140 levels. 86 00:07:41,380 --> 00:07:46,280 But we're not going to do this right now because we have way more important jobs to do. 87 00:07:47,320 --> 00:07:49,600 So if I right now print. 88 00:07:51,130 --> 00:07:58,120 And then you are real library dot, request dot. 89 00:07:59,810 --> 00:08:01,420 You are open. 90 00:08:03,590 --> 00:08:12,410 You are so open and after that, if I right again, YouTube actually HTP. 91 00:08:14,440 --> 00:08:20,680 YouTube dot com and timeout equals 30. 92 00:08:22,090 --> 00:08:24,170 Let's run it and see if we're going to get there. 93 00:08:25,090 --> 00:08:26,170 So here we get there. 94 00:08:26,170 --> 00:08:29,140 All the euro you find so important, so important. 95 00:08:29,650 --> 00:08:33,090 You are Aled Library, OK? 96 00:08:33,490 --> 00:08:35,440 And then they will run the comment once again. 97 00:08:36,160 --> 00:08:41,710 So you can see that here we simply return the HTP response interface. 98 00:08:42,040 --> 00:08:50,380 And actually this response gives us the data from the request that we made from the resource on the 99 00:08:50,380 --> 00:08:50,680 Web. 100 00:08:50,890 --> 00:08:52,750 In that case, a YouTube dot com. 101 00:08:53,620 --> 00:08:59,470 Also, we can use adjacent formats in order to do that, for example, if we import. 102 00:09:01,970 --> 00:09:13,640 Jason, OK, and they response equals who you are, no library, the record is. 103 00:09:15,270 --> 00:09:18,000 Doctor, you are open. 104 00:09:20,030 --> 00:09:24,470 And then Eurail Coleman by Mount. 105 00:09:25,650 --> 00:09:29,130 You caused 30 actualised put instead of your. 106 00:09:31,810 --> 00:09:33,400 HTP. 107 00:09:36,780 --> 00:09:41,670 And then YouTube dot com, so we have exactly euro here. 108 00:09:42,710 --> 00:09:43,290 OK. 109 00:09:43,640 --> 00:09:50,600 And after that, I can simply do g some underscore response. 110 00:09:51,110 --> 00:09:57,920 You quotes from Jason Load's response. 111 00:09:58,140 --> 00:09:59,770 Don't read. 112 00:10:00,110 --> 00:10:06,110 OK, so this another way to do it and we actually got an error here, so let's try to fix it. 113 00:10:06,590 --> 00:10:07,880 Everything seems correct. 114 00:10:07,880 --> 00:10:10,660 Maybe just the website that we are using. 115 00:10:12,450 --> 00:10:15,590 You may have the right to data in order to do the job on it. 116 00:10:15,860 --> 00:10:20,780 So let's give this step for now, because I want to show you something we're more interesting and this 117 00:10:20,780 --> 00:10:22,640 is specifically the status colts'. 118 00:10:22,880 --> 00:10:32,240 So usually the HTP provides us with a way to see the status of the response or the request we are making. 119 00:10:32,510 --> 00:10:41,050 For example, if I see a status of 100, this would mean that the response is informational. 120 00:10:43,230 --> 00:10:53,040 OK, for example, if you see a code of 200 dismiss success, which means that the government is accused 121 00:10:53,040 --> 00:10:53,680 of correctly. 122 00:10:54,120 --> 00:10:58,710 For example, if we see 300 dismiss redirection. 123 00:11:00,580 --> 00:11:14,320 Resurrection, if you see 400, this means claim error, and if we see 500, this usually means server 124 00:11:14,770 --> 00:11:15,260 error. 125 00:11:15,620 --> 00:11:18,870 OK, so these are all the calls that we could see. 126 00:11:18,880 --> 00:11:25,270 And let's try to do one operation or actually check what is the code of our response file. 127 00:11:25,300 --> 00:11:33,130 So if I do Python and they do restores that status. 128 00:11:36,630 --> 00:11:39,230 OK, let's redefine the resource once again. 129 00:11:40,310 --> 00:11:50,960 So so let me report once again the euro library and I will swim for the euro open so I can recreate 130 00:11:51,050 --> 00:11:52,110 what he already had. 131 00:11:52,490 --> 00:11:53,930 So let's run this. 132 00:11:55,810 --> 00:11:58,120 Actually, I watch You Tube. 133 00:11:59,110 --> 00:11:59,810 That's right. 134 00:12:00,280 --> 00:12:02,320 And now we can simply do. 135 00:12:06,100 --> 00:12:16,600 Response, the status, and it will get down to the status to which means that we successfully collected 136 00:12:16,600 --> 00:12:22,120 the data from our data source, which is quite good, and this is the way that you can check if you 137 00:12:22,120 --> 00:12:29,340 get the right data, because 200000, remember, means that we have a success in collecting the data. 138 00:12:30,730 --> 00:12:36,600 This was the last thing I want to share with you guys, but to have more to cover in this section, 139 00:12:36,850 --> 00:12:41,260 so thank you very much for watching that video and I will see you in the next one where we're going 140 00:12:41,260 --> 00:12:47,890 to cover how to handle exception using your old library's. 141 00:12:49,330 --> 00:12:51,970 In the network programming, thanks for watching.