Searching with experts, hello, everyone, when dealing with examples in order to be able to check
every element from an XML file, we need a cure or a tool called XPath, which and so it search every
element inside the next e-mail file that we enable.
So let me first open the pie chart because I just closed it.
But actually the first thing to do is to work a little bit into our terminal.
So actually, I will go back from the folder I am in and I'll go to Section four.
So let's tie pattern here.
So we go in python mode and let's do some operations with the experts to get.
So if we first record what we call it already from the last time, so we have with what to work in this
video, let's now write import requests that the response is, of course, and I actually copy because
we already did that in the LAX in the last lecture.
So here I'm going to paste the response from this website here.
So it's information on the XML file is going to be stored in the response.
OK, so here the root variable will contain the XML tree like we did last time.
And let me just base these variables here so we have all the website setup enabled for this project.
If you actually completed the other video and you didn't exit from Python mode, you actually be able
to simply continue from where we finished.
But since I had to exit this place overnight, I'm just reading the comments.
Were it already?
OK, so we're already here and Lamido now route dot x.
But in in the break a separate body for this is the board over the website and you can see that we get
Elaman body out and some others.
Usually this is how in Python or actually in the whole world I represented the other races of the different
websites.
So this represents the simplest xpath desperate expression and it simply it simply searches for the
children or the current element with a specific bug name.
So here currently the specific element that we are calling is the root element of the website.
And so because of the fact that the root element is on the top of the HTML element, for that reason,
we're returning actually the body of the website.
OK, so usno know the XML file is a three file.
So for example, if I would like to say some of the elements, I can do the following.
I can write root x part and then bodge slash div.
That's it, and you can see that we are getting a few elements this time, and this is because we are
getting the children body and the children as well.
OK, so this shows that the expert experts tool can actually much, much pull elements, not only one,
which is quite useful.
Now let's try to not think so outright ruled that X part and then I will write a one for either one.
And actually, you know what?
Let me open the actual website so you can see what I'm talking about.
Maybe it will be a little bit more intuitive for you.
So here's the website and I will open the inspector here so you can actually see the code in front of
you.
And let me minimize that window, because the code is what we are interested in.
So until until now, we the body was on the back of this and after that we can actually see the actual
header.
So if we double click here, you can see that we have our header number and so on.
So let's see now the header and H1, it will be the header one.
And you can see that also the header has a different tack or different element that is referred to when
we're assessing the Web.
OK, so also let me show you one more thing.
You can also can apply additional conditions to the elements and you can do this by rote dot exports.
And then in the brackets you can write div and then you can apply the condition with that idea.
OK, and you can see this right here.
So at idee equals double bracket content.
OK, and then let's close all the brackets.
That's right.
So if I run it, you can see another element in this, specifically the element of the content.
OK, so this is its tack.
And so I know that by seeing just this random number that it's not very intuitive for any human.
But before jumping into the extracting of actual information, let's see a little bit more of the possibilities
that you have with the Xbox to extract specific addresses of different tacks in the website.
So I will do now ruled that XPath and here I will show that you can specify the tag name.
So if I do this H1, OK, you can see that we're specifying the back of the H1 specifically for the
first div.
And you can also do another thing.
For example, if you want to specify the diff in the body, you can simply do what body slash div.
Two, OK, here we go to Nero because added to parentheses, so now we can see actually the element
of the first death in the body, actually.
So this is the second one.
My bet.
But, yeah, this is how you're actually using these statements here.
And actually, I'm going to open up another terminal because I don't want to lose the progress here.
So let me actually do one major.
I will press command today here.
And you can see that here we are getting other terminals or actually is that you can do new windows
because this actually doesn't work.
I will simply do new window.
And you can see that we are getting a brand new window here.
And from this window, I've actually located a folder that we actually created into the pie chart,
which is of Section four.
And then I will show you some additional files that you can create in order to work with XPath toolkit.
So let's go here and now actually go slightly closer so you can actually see and I will do some comment
in order to go to the right folder.
You can also set your folder.
OK, so once you're in the right section, nice.
Let's go back here to the code and let's create another file, which will be called Get the Version.
Or for this file, we're actually going to get a version of the website using the XPath toolkit.
So Python file and I will to get.
Version, OK?
And let's hear now import Ari and then let's import requests and then let's it from el ximo not e three
import HMO, OK, and then response will be equal to the response that you get in here.
We're going to get the response of the website and I will simply copy and paste it here.
So this is our website.
You can simply browse the video and just rewrite what we did already but are wrote actually the same
name, if you don't remember, into our terminal when we're doing the python mode.
So let's do now ruled equals HMO and the breakfast is right root.
Sorry, let's actually write response dot content.
OK, and then let's write title.
Next will be equal to rules, not fines.
OK, and here we are going to look for a hat because usually the information for the website is stored
there and then they will.
Right?
Fine.
So we are going to use the find function.
So find.
Title and just platers text, OK, so this is how you write this in Python and then let's try it if
we don't search and then let's try it here.
You 201 see not star you 210 one D comma.
Title, text.
OK, so it is the same variable that we did.
OK, so in that case, let's do release equals to RB dot search.
And here we can write again you to see the star.
OK, slash you to one the.
OK, Colma.
Title, underscore, text, dot group.
OK, so if this happens more than once, who just like to group it and show one element.
So let's do now p text.
Equals to rules that XPath and here is the first time we're going to use the export function and here
I will do def.
Actually, let's do a double slash diff, and here I will do the inquiry for the content, so I will
do.
I do, of course.
Content, then let's close the bracket, slash the one that's it, the zero dot text.
OK, and then let's the version.
So version equals P underscore text dot split one.
And then let's write the print code name and then let's write slash and version.
OK, and here the last thing I would do is simply to formatted so the format and then I would write
through release release comma version.
So.
Here's how we're going to show their release, the version.
After all, and the first of have code name, OK, and this will be the release and then version, which
will be the actual version.
So just place here, guys, because I found that they skipped it and basically that was it.
This is the code.
So let's save it here and let's go up there and I will just hear right.
Hashtag exclamation mark user slash bin slash Ian V.
Python three, so it knows actually which file to use.
OK, so save that and let's go to our terminal and here we are already in the folder.
And if you right away, you can see that you have the gate version on file.
So let's write Python get version, not pure, white and OK, here we have an error.
But this is not a big deal because now we're professionals and we can fix it.
So let's see what it is.
So yes, here I missed that is so you know, we imported the requests package and instead actually I
wrote here responses and should be requests, OK, requests that get.
That's correct.
So let's from the code now and you can see that now once we run it, we can see that the code name is
Buster and the version is standard then.
So we extracted the correct information from the website and this is the way that you can do it.
Actually, I don't think the lines are too long for getting this information.
So what we do is here we use the regular expression XPath in order to to pull out the virtual name and
split it into different fields.
So there are also other usages of XPath and you can usually use it to get images and links from the
Web page.
But for that, we're going to talk actually tomorrow because this video is already too long.
So thanks very much for watching, guys.
And bear with me to the next video where we're going to use some advanced methods in order to get images
and pages from the Web using XPath.
Thanks for watching.