Passing H.M.S. Hello, everyone, today I'm going to teach you how to pass the HTML files and to do
that work usually need to use a third party package that is called XML.
And this package is nothing more than simply an XML parser.
This package is a quick way to navigate between documents.
And actually this is one of the best XML parser that you can find out there.
So this package can be basically installed in every platform that supports Python.
So this means that nothing can stop us to use it in our project.
So let us install this platform and after that, they will show you how we can actually pass an HTML
file.
So I will go here to the Edem and actually let me first go to the pie charm and create a section for
weight of our file.
So when they create Section four here, we will collect all of our files for this section.
So the section.
For OK, and you can see it now, you have here the file for Section four and actually also create Section
one two and we're going to add the thousands are already used in there.
So I will create directory section two.
OK, so I will simply pass everything we've done so far into that section.
Here we go.
And that's it.
So you can see in that way it is actually way more organized.
So let me close all of those files here.
And after that, and we can go back to the terminal and I will show you what you need to do.
First of all, let's go to the Section four files.
Here we are in Section four.
And before actually running the files, let's to by install El Ximo.
OK, so as you can see, I have it already installed, but if you don't have it, you can install it
with that comment and let's actually do buy in stole El Ximo.
Yes.
And then I will just reinstall so you can see how easy it is.
That's it.
This is how much time it takes to truly one second to install the XML package.
Anyways, let's now continue with writing into the Python command line.
So write Python and then let's import import resources that they don't mistake Greece or actually this
the wrong package.
We need to import three coup requests.
OK, that's fine.
And no, let's first download a page.
Which is going to be obviously into the general format.
So how do we download page Lizardo Rorris bonds will be equal to requests that we get and here I write
the name of the page, which will be age Tepes w w w dot.
They've become dot org re.
Releases stable slash index.
Not even the HMO, that's it.
So everything is passed, we downloaded this page.
Now let's choose the package that we already implemented.
So let's draw from Elex, smell that, eat three import HMO package.
OK, and then I read ruled.
Equals HMO response, not content.
OK.
So by using the HMO function, we're using a shortcut that reads the HTML file that is passed to that
function.
And from that HMO, we're producing an XML tree.
So I want to note here that we're not passing the text of the response, but the whole content into
the HTML so we can have the whole content when we created the XML file.
Now let's right here Brocket e not Thack.
For E in ruled.
OK, and you can see here that we have hit and bodgy of our route and now let's right route dot find
and then head dot find in here laterite tyto.
That's.
Text and OK, I've got an error here, so let's see what it is so rude, don't find head.
So there is that item at the parentheses here.
So after title, when I put in our parentheses, you can see that we're printing the actual text content
of our website.
So we're basically printing the heads, which is Debian booster, and then we get the release information.
So action against.
Let's go now to the Web page because I want to show how the actual page looks like and from where we're
actually getting the information.
So this is the page that we're actually using.
And let let me inspect the code so you can see that basically this one here is the HTML.
OK, and here is the head and here's the body.
OK, so if you actually go back to the terminal, you can see that up here where it is, where we run.
What are the sections in our HTML file we got exactly here, which is this one here and then we've got
the body.
OK, so this is how the file is representing the website and this is how we're getting the information
from the website into Python.
So let's open actually the sections.
And when they open the bottom and when they go to the content here and when they open it, you can see
that the hero of the code of the content is the Debian boaster release information.
And actually this is exactly what we found here.
OK, so this is exactly what we've got.
So the only reason why we got this information is because up here we selected that we would like to
see the actual content.
So response, not content of the website that we select here.
So the website that was left to pass through the HTML to the response and then from the response we
got to the content field and whilst we display it, we got the exact header of the content of the content
field.
OK, so here we did hit and this is the header one and we found the title.
So this is how you can basically take any website and find us here and any other relevant information
that you would like to use.
So let's write another thing.
Let's write the rules dot find and then.
That's right body.
OK, that's fine.
All def OK.
And then they will write one here dot find and then B dot text and that's it.
So you can see here we found Debian then dot then version and again this is part of the body and I will
show you exactly where this part is right here.
So we'll go to route find OK and we'll go to the board here.
So we're within the body then if one finds P and you can see that here we have Debian, then then OK,
exactly the content under the pack then under the P.
Sorry.
Quite simple, right.
So there is actually one quite unpleasant disadvantage here.
And this is because when we're searching by def, OK, there is quite a high chance Advtech that has
been inserted before the actual section that we look for.
So if we're sorted by David Thack, we might not find always the right place.
So in many cases it is better to search not by the VITAC but by the idea.
And here in that case, the idea is content.
So in most of the times you would prefer this way, because in that way you're sure that there was only
one content place or there was only one place or there is only one title piece?
Right.
There are not multiple areas like this.
But the difference, as you can see, one here are quite a few.
So to address this issue, we're going to create a simple called a file into a Section four, and this
will be our first file.
So let's create the Python file and I will create it the.
Because who are going to go to the go website, so let's write from and let's get closer a bit so from
AWEX a.m. dot H.T. and they'll import from string.
OK, let's fix the syntax here.
OK, and also to string.
OK.
And also from El Ximo, that HMO import pass and submit underscore for.
OK, then let's import requests, OK, and let's create in our response, equal to requests that we
get and here all need to write, as you can see, the bureau of the website.
So I'm going to write right here, h t t p.
S book, The End Goal, dot com and then from page in the right forum.
String response, dot text.
OK, let's move it a little bit up.
OK, so after that, that's right from or actually right form.
Ecorse form.
OK, form here, page.
So the previous file dot forms.
Zero.
OK, and then our write print.
To string.
For.
OK, and then let's right page equals Paris, and here I will write again, the euro, so the euro will
be age.
TTP, slash the look and go dot com.
OK, and then let's try to not get ruled.
OK, we're ready here.
That's right, page, OK, page that forms.
Zero.
That's.
Fields fuel equals Biton.
And actually put this in parenthesis, OK?
And we're almost done, actually, so let's write the result.
OK, this will be a variable, so result here will be equal to pass submit form.
Page dot forms.
Zero not get ruled.
That's it, and then let's right print to string the result, that's it.
So everything looks good.
Guys, let's save this file and let's now go to the terminal and let's exit the python mode.
And as you can see, I'm in Section four so I can simply run this file by writing Python and then The
Pure Way, and it will run for a second.
And you can see the enormous size of the file, how big it is.
And obviously this is because we cannot display the whole XML in the way we would like to see it.
But if you see just the first part of the file, you can see the object and you can see the idea, which
is the search from home page.
You can see the class that the search and all the other elements of the header and of the form that
we obtained online.
So this is the way that you can actually do it.
So this is what I wanted to share with you for today, basically how you can pass HTML file into XML
file.
I hope it was quite useful specifically because here we didn't use any APIs that.
Guys, thanks very much for watching and I'll see you in the next video.