Content types and extracting URLs.
Hello, everyone.
Today, we're going to talk about content types and let's first explain what is called the content types
and then we're going to do some tests so you can see visually on experiments with this type of topic.
So so as HTP can transport basically any type of data to the server, usually use the content type in
order to add in the header and information about basically what is the type of the file that we're obtaining
from Internet.
So having done that, pull data basically helps us to know how to deal with it.
You know, and this is because you're actually not going to be dealing with picture in the same way.
For example, how would you deal with a text file?
Right.
So for that reason, it is very important to have the content type and to be able to know how to obtain
it.
And let's actually open the terminal and I will show you some examples of that.
Now, if I write Python and so enter the Python terminal, we can assume the right response because
to you are l open.
And then I will write HTP s or HTP YouTube.
YouTube and dot com let change here the parenthesis to just a single one, and let's actually import
the Eurail.
Actually, in.
Let's do from Eurail Library.
Import.
You are real open, actually, from your elaborated request.
Request.
That's it.
And also, let's import.
Your library.
That's it.
So once you have both of those libraries, let's repeat the.
And let's repeat their response excellent with the YouTube dot com, and you can see that now the request
is accepted.
So let's do a response.
Response, don't you get here
and here, would like to do the content and type.
OK.
So if I do it, you can see that the content type is text here.
Right.
So here I can see basically what is the content type of the page that they assess in YouTube dot com.
So we consider this material.
Obviously you can.
Explain your files, so since you already know how to do that, let's talk a little bit about links
or you know that every website has many pages which refer to links and sometimes maybe you would like
to see all those things, right?
Well, in that case, we can use the euro library in order to see or extract some of those links.
And obviously, this is part of the python packages.
So you can get more information to this Web page here, the HTML parser.
So if you're interested, simply go to this page and talk to the Python dot org and HTML parser.
OK, because this is what we're going to use in order to extract links.
And here you will see many functions, even functions that are actually not covered in these videos
if you feel the need to use them.
But now let's go to the Python directory here.
And let's create another file so the family court extract links, so vital file pics.
Tarak.
And underscore links.
OK, so let's create a new python file called Construct Links, I will say that.
And let's right now, so I actually let's get a closer look and see, then I will write user.
Slash, we've been slashing the fee to assist a -- in Python three and then from H.T. a.m..
Not pastor of the total here, we're using the pastor comment and the middle HTML parser class, that's
it.
And then I'll import import.
Obviously you are old library dot request.
And no, let's create a class so the class will be called my.
Pass her and pass past age HTML parser.
OK, so from the class HTML parser, we're basically going to create the class by password.
OK then.
That's right.
Dear Shindou underscore starting OK.
And here you need to define a few other attributes.
Self obviously for the current item pass to the class action limit.
Same column here.
So self to the current item.
Pass the class then Thack and then.
Eighty hours, four attributes.
Then let's do if.
Doc.
It costs a.
So in that case, what he would like to do is to do a statement for A in attributes if.
A zero is equal to H, r, e, f, and then there's Dooling.
You cause a a.
We're actually a while here, OK?
The first attribute of a.
And that if a link that finds.
HTP.
So if you find the HTP link higher or equal to zero.
We would actually like to display it, right, so would like to present a link in that way, we're actually
going to pass in print of the HTP links that are.
And related to the Web page to assess soil, the new.
Parra's.
Equals.
By Pastor, OK?
And then I will do a you pass the feed.
Link.
OK, so this is going to be recursive function because we call the function inside itself until we get
to the final result or until the number of things finish.
So here are two Eurorail equals to HTP.
YouTube dot com.
OK, then request.
We'll do quote to you, RL library, not a request.
OK, not who you are so open and I will write to the jury that we passed to the program.
OK, then let's the password.
Equals my
sorry.
Bye bye bye.
Pastor.
OK.
In the pastor will be actually don't feed.
We request so as you can see here, we're quite a corporate passer from the last paper, sir, and then
I will do request to read.
Dalts.
Called.
And then out to you.
T.F. Dush eight.
And that's it.
Done.
So let's say that I seem to go back to the terminal, so I would go to the terminal here and I will
exit the python mode.
OK, so here's the same resources.
If we're right, Airways, you can see the file extra actually misspelled.
But anyways, extract links.
So I will do Python.
Extract links.
Let's run it.
And here you can see all the different pages that are related to the YouTube.
So you can see here the page about you see the page about slash press, about slash copyright creators.
And then we also have the developers go dot com YouTube.
So you can see that this page is also related since YouTube is owned by Google.
Then you have the politics, Google, YouTube about policies and so on.
And finally, you have this weird looking page.
So let's put it in the browser and see what's inside there.
So let's add the page.
And.
This is how this weird looking page looks like.
Apparently, this is one of the main pages of YouTube I never seen before, but you can see that we
can actually find and assess every page that YouTube owns and this place to the to the users.
So so I hope, guys, this picture was informative for you.
And if that was the case, please continue watching the rest of all the videos because they are also
that interesting.
Thank you very much for watching.
And I'll see you in our next video.