Okay, guys, so now it's time for us to scrape the rooms we have or.
No, sorry.
The number of guests that's allowed in the rooms.
I've removed all the code I showed you in the previous lecture because I just wanted to show you why
we are going to use regular expressions now.
Um.
So.
Let's get on onto it.
So on my right side, I have my favorite site for checking regular expressions.
And I'm going to be showing you in a moment how we are going to use this.
Let's first try and see.
Let's first just try and run the script.
So I'm just going to copy this into a blank page while the scraper is still running new pages here.
I'm going to go into Chrome Developer Tools.
And now.
Each of these elements in is contained inside a div with an ID that is called room.
And basically it's all the text for the posting we have inside of this selector.
So if we go room dot text, we get a bunch of text here and up in the top we have the information that
we're looking for.
Free guest, one bedroom, one bed, one bath.
So basically, we're going to take all of this text.
And put it inside of my sight.
Reg 101 to test the regular expression we're going to write.
So let's try and see.
So if you're not familiar with regular expressions, it's basically a way to find patterns inside of
text.
So, for example, the plus means we are looking for any kind of number of any length.
If it's just D, it is just a single number.
So if we look for the plus and guest.
Then we are going to find just the text here which is says free guest.
Now notice that I'm not putting guest behind because some rooms may be just have one guest only allowed.
So if we have the guest with the S in the end it's going to not detect a text if it has only guest.
So just to make an example, if it has one guest, this regular expression is not going to detect it.
So we need to have only guest instead.
But it is going to be fine for what we're using it for.
So we see that this regular expression is working fine.
Obviously, if the, um, the owner of the room is typing somewhere else, uh, a number and guest after,
we're going to detect it as well.
But most likely the information we want is right in the top of this text.
So it's highly likely that the first result of this regular expression is going to be what we want.
So with that being said, let's just copy that regular expression we have here and go inside of our
code.
So let me just make a room text variable for the selector containing all of the rooms text, and then
we are going to run a regular expression on that and return the results.
So let's see.
We can run.
Guest matches.
Room, text.
Match.
And then we put in our regular expression with two forward slashes and type in our regular expression
like so.
And just to make sure that we're not going to get a index out of bounds error, I will check if the
guest matches has a length over zero.
And if it does, we will assign a variable, let's call it guest allowed by default.
I will say not applicable in case we can't find this regular expression and I will say guest allowed
equals guest matches and we get the first match.
So that should be good enough.
Let's try and print the guest allowed.
And let's also just return the values we have gotten so far price per night and guests allowed like
so.
Let's see how it run.
Let's go and run this script.
Hmm.
That is.
That's odd.
It's not running.
I notice sometimes that it is not running all the time, and we'll try and debug why that is happening.
Let's try and run it again.
So now it seems to be running.
So there we go.
We get the crowns and the number of guest.
I think the reason why the index page is sometimes getting stuck in this scraper that I've noticed that
sometimes is because we don't have the wait until in that page.
So let me just go ahead and add that as well.
And, um, yeah, as you can see, it is getting the price and the number of guests that is allowed
in the room seems to be going nicely too.
Guest four Guest.
Yeah, it seems to be running just fine.
Okay, everyone, in the next section, we are going to get the rest of the values, but it is pretty
much going to be just like we are getting the the guest, the number of guests allowed.
So see you in the next lecture where we get the rest of the values.