WEBVTT

00:00.060 --> 00:02.540
Used a copy selector function.

00:03.050 --> 00:10.400
So I usually try to figure out myself first how I could select the element and I end up with shorter

00:10.400 --> 00:11.720
CSS selectors.

00:11.900 --> 00:14.390
It sometimes is a little.

00:15.070 --> 00:16.840
Easy to read, I think.

00:17.080 --> 00:19.240
But you can also just use this.

00:20.460 --> 00:27.120
But if I had to come up with like my own manual way of figuring out how to select this, you could go

00:27.120 --> 00:32.780
and say, okay, it is inside the P element with the class attribute group.

00:32.790 --> 00:34.230
So you can say.

00:35.360 --> 00:39.140
And p dot attribute group.

00:40.550 --> 00:42.620
So that is that element.

00:42.620 --> 00:48.230
But then we need to go and say, okay, we also want the first span element.

00:49.630 --> 00:55.900
And then you can use you can get some inspiration from the selector that Chrome tools gave you.

00:55.900 --> 01:00.340
And you can see here it says span and then it says env child.

01:00.340 --> 01:07.090
So that means the first child, which is a span from this parent element, then we can say.

01:07.800 --> 01:08.070
Okay.

01:08.070 --> 01:10.740
So let me show you the text first from this one.

01:12.130 --> 01:13.510
That looks like this.

01:13.690 --> 01:15.730
It gets all the elements here.

01:16.060 --> 01:17.770
So all of these ones.

01:19.590 --> 01:21.750
But we want just a first child.

01:21.750 --> 01:24.090
So the first span child.

01:24.120 --> 01:26.520
That means you can do something like this.

01:26.700 --> 01:30.480
Span inf child.

01:30.480 --> 01:35.370
And then you say the first child and then we just get this instead.

01:36.330 --> 01:42.180
And then again, if I wanted to get just the bold element, we can try and do that so we can say, Just

01:42.180 --> 01:43.440
give me the bold.

01:43.860 --> 01:46.410
Then we can use the child selector again.

01:47.390 --> 01:52.970
Which is this one and say B, and then we just get the compensation.

01:54.630 --> 02:01.740
So that is, as you can see, a shorter CSS selector to use rather than this one.

02:02.710 --> 02:04.450
But they both work.

02:04.450 --> 02:07.150
So if you want to use this one, feel free to use it.

02:07.150 --> 02:08.770
If it works, it works.

02:09.580 --> 02:15.940
I just like to fiddle around with myself and see if I can get a smaller CSS selector usually.

02:16.680 --> 02:21.300
So I'm going to go ahead and use my own CSS selector here.

02:21.690 --> 02:25.110
Feel free to use the one from copy selector if you want to.

02:25.320 --> 02:30.990
And then we're going to go and add it to our object inside the scrape job descriptions.

02:32.120 --> 02:39.080
So in we can see here, we can say listings on the I index and say the compensation.

02:40.070 --> 02:46.460
Is equal to compensation and I need to declare the variable first compensation.

02:47.680 --> 02:54.550
And we can say const compensation equals my CSS selector.

02:55.290 --> 02:56.190
This one.

02:57.020 --> 02:57.860
Don't text.

02:58.720 --> 03:00.400
And that should be it.

03:00.430 --> 03:05.620
Now I'm going to do another console log just to check if I'm getting the right data.

03:07.670 --> 03:13.010
And then we can say Node index.js and we can check out if we get the right data.

03:16.290 --> 03:22.410
So now it's going through all the job descriptions and I can see the compensation is down here at the

03:22.410 --> 03:24.090
end of the console log.

03:24.090 --> 03:28.440
So competitive salaries depending on experience and so on.

03:29.720 --> 03:35.600
So people that is how we get the compensation from all of these job descriptions.

03:35.630 --> 03:41.600
It was probably the most complicated element to select so far in this section.

03:42.220 --> 03:49.690
Because it didn't have any CS class in the element that we can just easily select like we've done before.

03:49.720 --> 03:56.740
We had to go through a little child parent nest in here where we have to select first.

03:56.740 --> 04:00.910
We selected the P element because that has a class.

04:01.090 --> 04:06.250
And then we said, okay, give me the first child and then give me the child element.

04:06.250 --> 04:08.020
That is a B element.

04:08.850 --> 04:11.010
So a little more complicated.

04:11.010 --> 04:14.640
But sometimes you have to do that and get through with it.

04:15.180 --> 04:19.770
So in the next section, we're going to look at how to save this data.

04:19.770 --> 04:23.340
We are now scraping onto a MongoDB database.

04:23.340 --> 04:26.580
And yeah, that's going to be a lot of fun too.

04:26.580 --> 04:28.620
And I'll see you in the next section.
