Consuming co-op services with your library.
Hi, everyone.
Welcome back to the course.
Today, we're going to talk in the section about programming in the Web.
Using the HTP protocol, you learn how to make requests on the Web and retrieve Web resources.
You be trained here, plenty of example requests.
You will be using the euro library and you'll be working with different forms and cookies over the web.
So in this section, you're basically going to gain a strong understanding about the Euro library package.
You understand how to use the request package as well.
You learn how to handle forms using the euro library and the requests with Python three point seven.
And actually, we're going to use some of the newest Python version, which is going to be three point
nine.
You will learn how to handle cookies with the same packages.
And finally, we're going to talk about the HTP and the HTP is authentication medal's.
So let's go to our terminal and let's get started.
Now, let's pull up the terminal and here's our terminal.
Let me actually make it a little bit bigger so you can see better.
So here's our terminal guys, and we're actually going to run some files in order for us to start to
think requests and cookies.
So, as I said, the first four stores that are actually going to use the library and basically the
library allows you to access any resource that is published on the network, such as files, pictures,
directories and so on.
It's a very powerful tool and it uses the protocol HTP in order to assess these files over the web.
Now, how important legible to python molds?
Here we're are, Baltimore, and you can simply import.
You are a liberal, OK, and you can see that we don't get there.
So this is the way you can import it.
And also if you get there or here, this means that the liberals probably not installed in your computer
so you can write them pipe install you R.L. Library, and if it is not installed, it will immediately
install your computer.
But us here is a library that is installed.
Now, you can see that I'm getting the message that I don't need to install it.
So let's go to Python Molt again.
So when we're talking about the library, there are basically four functions that are covering this
library.
The first one is the request which simply opens and the reads are Eurail or some other is over the Web.
Then we have the error which contains the errors generated.
When you making the request, then you have the past two or cold parts, which basically converts the
euro into the readable information for you.
And finally, do we have.
The report.
Paris, which basically covers the route, takes files and as a matter of fact, if you go to this website,
Dr. Dot Python dot org, and if you search for the euro library DOT request, you can find all the documentation
for the Euro Library DOT request and actually find all the functions related to it.
So whilst we complete this section, if you want to do some additional functions, this is a great place
to go and see what each function is doing and simply use it for your needs.
This here is the euro of the library, so you can simply type it in your browser and you will gain access
to it.
For example, if I search here for you are now.
Open, we're getting here the open function, and you can read the documentation for it, so here Dysfunction
Open is simply creating a file similar to a text file that is extracted from a Eurail.
So what the system does when you use this common here, it basically converts or reads the euro and
convert it to a file.
And this object has many different methods, such as rethread line read lines, clothes and so on,
wants to create the file.
You can basically manipulate it in a way you like.
For example, let's right here.
So now we're in a python mode and let me show you how we go there.
So let's write Python and once were taken Python code.
You can separate from U.
RL Library DOT request.
So request import, you are open.
OK, so now we imported the euro open option from the euro, Labrador's request, and then if we're
right, the response, so this is going to be a variable.
So we're suppose equal to the euro open.
OK, and let's type some example address on the Web that we would like to explore.
For example, let's up one of the most famous websites, a YouTube dot com.
So if we do H.T. be.
Slash, slash, w w w dot, YouTube and dot com.
OK, and if we're on that, OK, we're getting nearer here, let's see where it is.
Yes, here I misspelt with the euro open, so let me pick it up and now I can see that we're not getting
on there, but we're also doing this painting because we need to call the variable that we just created,
which is called response.
So if I write a response here, you can see that we already called the HTP don't claim HTP response
and we have that resoled object.
So this means that we already passed the data from YouTube to that object.
And if we're right, for example, now response dot red line.
You can see that we can perfectly read the data that we received from YouTube, so by Ridgeland.
You know, we usually receive an HTML file once we get the YouTube dot com and HTML file goes through
the response object.
So here by writing Crillon, we simply get the header of this HTML file.
OK, I mean, the way that this file was written here, it's not very understandable because there's
just written in the same line.
But if you put it in the correct HTML converter, you'll see it very well with a different annotation
levels.
But we're not going to do this right now because we have way more important jobs to do.
So if I right now print.
And then you are real library dot, request dot.
You are open.
You are so open and after that, if I right again, YouTube actually HTP.
YouTube dot com and timeout equals 30.
Let's run it and see if we're going to get there.
So here we get there.
All the euro you find so important, so important.
You are Aled Library, OK?
And then they will run the comment once again.
So you can see that here we simply return the HTP response interface.
And actually this response gives us the data from the request that we made from the resource on the
Web.
In that case, a YouTube dot com.
Also, we can use adjacent formats in order to do that, for example, if we import.
Jason, OK, and they response equals who you are, no library, the record is.
Doctor, you are open.
And then Eurail Coleman by Mount.
You caused 30 actualised put instead of your.
HTP.
And then YouTube dot com, so we have exactly euro here.
OK.
And after that, I can simply do g some underscore response.
You quotes from Jason Load's response.
Don't read.
OK, so this another way to do it and we actually got an error here, so let's try to fix it.
Everything seems correct.
Maybe just the website that we are using.
You may have the right to data in order to do the job on it.
So let's give this step for now, because I want to show you something we're more interesting and this
is specifically the status colts'.
So usually the HTP provides us with a way to see the status of the response or the request we are making.
For example, if I see a status of 100, this would mean that the response is informational.
OK, for example, if you see a code of 200 dismiss success, which means that the government is accused
of correctly.
For example, if we see 300 dismiss redirection.
Resurrection, if you see 400, this means claim error, and if we see 500, this usually means server
error.
OK, so these are all the calls that we could see.
And let's try to do one operation or actually check what is the code of our response file.
So if I do Python and they do restores that status.
OK, let's redefine the resource once again.
So so let me report once again the euro library and I will swim for the euro open so I can recreate
what he already had.
So let's run this.
Actually, I watch You Tube.
That's right.
And now we can simply do.
Response, the status, and it will get down to the status to which means that we successfully collected
the data from our data source, which is quite good, and this is the way that you can check if you
get the right data, because 200000, remember, means that we have a success in collecting the data.
This was the last thing I want to share with you guys, but to have more to cover in this section,
so thank you very much for watching that video and I will see you in the next one where we're going
to cover how to handle exception using your old library's.
In the network programming, thanks for watching.