WEBVTT

00:00.460 --> 00:06.790
Okay, So now we were able to get the company name and all we need to do now to get the contact column

00:06.790 --> 00:13.150
and the contact column is just to do the same thing we have here just with a different index instead.

00:13.420 --> 00:21.280
So let's just copy this line here and paste it down two times below and change the index to one and

00:21.280 --> 00:24.490
we change the variable name to be contact instead.

00:24.790 --> 00:30.910
And down here we change it to be two and change it to be country instead.

00:30.910 --> 00:32.830
So then it fits with the table.

00:32.830 --> 00:37.180
And now we need to put all of the results.

00:37.180 --> 00:45.550
For every row we have a object we create, let's call it const and let's call it scraped.

00:46.470 --> 00:47.040
Row.

00:47.820 --> 00:54.750
And let's say that it is this object here with the company contact and country.

00:57.570 --> 00:58.710
And we save that.

00:58.710 --> 01:05.130
And then we need to save it into an array that we declare up here before we begin the loop.

01:05.130 --> 01:13.350
So up here we can declare an array we call const scraped rows, just an empty array.

01:13.350 --> 01:19.350
And then for each row we just push this scraped object into the array.

01:19.380 --> 01:21.570
So scraped rows.

01:22.290 --> 01:23.610
Third push.

01:24.400 --> 01:26.620
Scrape row.

01:28.090 --> 01:34.930
Now, once the loop has finished, we can try to do a console log to see how the array is looking like.

01:35.650 --> 01:39.520
Console log scraped rows.

01:40.590 --> 01:45.240
Let's save that and let's try to run it inside Node JS.

01:45.690 --> 01:47.640
Node Index.js.

01:47.670 --> 01:48.720
And here we go.

01:48.720 --> 01:52.800
So now we can see all of the table data.

01:53.490 --> 02:01.110
You can see the first row here has empty data inside of it because it has the element instead.

02:01.110 --> 02:03.570
But we're going to fix that in just a moment.

02:03.720 --> 02:11.670
But as you can see, we have all the other rows here with the company, contact and country correctly

02:11.670 --> 02:12.750
declared.

02:12.780 --> 02:19.440
Let's try and skip the first row we have on top so we don't have this empty object here.

02:19.440 --> 02:25.470
So we can say if the index equals zero.

02:25.470 --> 02:30.210
So that's the first row we have up here with the elements.

02:30.360 --> 02:35.040
If that's is the case, if that's the case, then we just say return true.

02:35.040 --> 02:42.970
So then then we skip this this iteration of the each loop, this, this row.

02:43.000 --> 02:43.960
We skip that.

02:44.650 --> 02:49.270
So now let's try and run it again and see what happens here.

02:49.360 --> 02:55.090
So now we have all of the rows, but without the empty data at the first row.

02:56.400 --> 02:57.630
Okay, so that's it.

02:57.630 --> 03:04.920
That's how we we find out how to build a selector with chrome tools and how to make sure it works inside

03:04.920 --> 03:09.950
Chrome tools and then how to transfer that into NodeJS.

03:09.960 --> 03:16.860
So now that we have it inside of NodeJS, we can build an API, we can deploy a periodic scraper that

03:16.860 --> 03:25.140
we can make, so we can make it scrape a page at every hour, every day, every week or however however

03:25.140 --> 03:26.250
we want to do it.

03:26.610 --> 03:34.290
And so now we can scrape websites without having a browser open and pasting pasting in code every time.

03:34.800 --> 03:41.790
And we can save the data to a database in MongoDB or save it to a CSV file and so on.

03:42.090 --> 03:49.020
So I hope you enjoyed this section and if there's any questions or if you're stuck with anything, let

03:49.020 --> 03:49.710
me know.
