Okay, everyone.
So now we are getting the number of guests that each room can accommodate inside of the listings.
We also want to get the bedrooms, the baths and the baths.
And the way we're going to do that is pretty much the same method as we are using in here.
So if you want to go ahead and do that yourself, get some practical exercise out of it.
I recommend that you pause the video and try to do that.
One thing to keep in mind before you do it is that I made a mistake here, because if we don't return
any matches from this regular expression up here, this value becomes null.
It doesn't have a length of zero, so you just check if it is not null instead of this.
Okay, so if you want to do this exercise yourself, go ahead and pause the video now.
And now for the rest of you who are lazy or just want to see how we do it, we go ahead and I do it
now and you will follow along with me, of course.
So we have we will write a function called return matches.
Because what we're doing is so similar to this.
And so we pass in the room text and the regular expression we're going to test and we have the regular
expression matches which rerun on room text with the regular expression.
And by default, we're going to set the result here of non-applicable and.
Just going to make the text a bit bigger for you.
And then we check if the regex matches is not null and if it's not null, then we just return the mean.
We set the result to be the first match.
And if we don't, I mean, if the regex matches is null, then there's something wrong or our regex
is not working as much as we want to.
So we return a no regex matches exception exception and we say no regex matches found for the regex
match we're trying to use.
So we can debug it later and look at the text and so on.
And finally we will return the result.
Okay.
And so we're going to go ahead and delete all this and we'll just say return matches, pass in the room
text and the regular expression, which I just deleted.
And that was the plus guest.
All right.
And actually we're supposed to be guest allowed, not guest match.
And yeah, now we can go ahead and write for the bedrooms.
Return matches.
Room text.
And we pass in a number.
I expect it to be a number and bedroom and pass.
Return matches and then a number and path.
Then we have bats.
Also return matches.
Room Text.
Bit.
Yeah.
So and then I instead of having these console log down here, I want to return an object with all of
the values we got here.
That's.
And then instead I want to say const result.
Here.
So the the object returned from the method here is coming down here and we want to console log that
instead.
And let's see.
So I also want to if there's an exception, it's going to throw a mean display this error so we can
see what regular expression is at fault here.
And I also want to show the I also want to see the URL so we can go and check the page that's failing
and I'll put that on top of the error.
And another thing I think that, oh, I forgot to put in the price per night in my values.
I think that's pretty important and.
Okay.
And so the URL I also want to pass in the room text in my exception if I got an exception.
So I will write console error room text and now room text.
We need to.
Actually, I forgot to have my selector here.
That's a mistake.
You probably have it in your.
Code.
That's just my mistake.
Then I deleted it.
But we actually need to move this room text variable.
To the outer scope so we can display displays it.
Display it inside of the catch here.
Like that.
And let's see how it goes.
Okay.
Room Testmatch is not a function.
Yeah, that's because I need to have a text on.
Sorry, guys.
That is probably only my code that has that error.
I don't know why I missed the room text definition.
Okay, so let's see.
One bedroom, one bath.
One bath.
Yeah, that seems to match what we have.
And okay, so we get a error here.
You see, we get no regex regex matches found for path.
So if we go ahead and look at this listing, we see it says one shared path.
So the regex match of path or number space path is going to fail on this example because well, it's
looking for a number and a path.
And well, you can make it into an optional word instead.
Let's try and copy this.
Let's see.
Am I getting it all?
Is this all of it?
Let's see.
It looks like it's missing the values we want.
I can't really see those.
Yeah.
Okay.
It's up here.
So, uh, let me see.
So we have baths, right?
And that did not match or does not match this one.
So maybe if we put in.
Bath as an optional word.
It can work.
So I put the word in parenthesis and a question mark after.
Let's see if it's still the text.
One bath.
It doesn't.
Maybe if I have question mark before.
Uh, come on, Christian.
Mark.
After.
Oh yeah, that's because I have a space in front.
So there's like two spaces.
So if I put space here instead, it's going to detect both of them.
And now we're kind of getting into a, I would say, advanced of, of, of course regular expressions
can be a lot worse than this, but, um, we're, we're getting a little into regular expressions now
and there's, there's other examples that you're going to run into where your regular expression will
fail in these cases.
So some of the rooms also just have studio.
It just says studio here.
So we could also make a or clause for studio here.
However, I think that I don't want to make this into a regular expression course and go into that much
detail.
I think you guys by now are getting the point of how this works.
So guys, this concludes the section on puppeteer scraping.
There's a lot more functions inside of Puppeteer, but I think we covered the most important things,
which is sort of getting the page and and parsing the HTML, the markup so we can get it.
Obviously the the most important feature of these browser automation automation frameworks that you
got like Nightmare JS and Puppeteer is that it's going to render the JavaScript so pages that we normally
can't see, like Airbnb is now visible to us.