WEBVTT

00:01.920 --> 00:02.430
Okay.

00:02.430 --> 00:09.750
So I got a question from someone who saw my previous video about the Craigslist scraper.

00:10.380 --> 00:13.380
Um, this is from Shark Tank.

00:13.470 --> 00:16.020
Me or how you pronounce it.

00:16.320 --> 00:19.740
He asked for confessing his love to me.

00:19.740 --> 00:24.000
He asked if I could make a video about going from the array to a CSV.

00:24.600 --> 00:27.510
And of course, I will show you how to do that.

00:27.510 --> 00:29.340
It's super easy.

00:30.290 --> 00:31.730
Um, first.

00:33.120 --> 00:37.590
You need to have the scraper project as we did in the last video.

00:37.590 --> 00:47.340
If you haven't been following the video, then you need to get the project from here inside of the GitHub.

00:47.370 --> 00:54.060
I will link the GitHub in the video description or as a Udemy resource for this lecture.

00:55.140 --> 01:02.160
Um, then you get the project and you should end up with a project looking sort of like this.

01:04.200 --> 01:04.680
Okay.

01:04.680 --> 01:07.260
So we have.

01:09.100 --> 01:13.840
We have this function down here for Scrape Craigslist.

01:13.870 --> 01:20.930
And what we're going to use is something called objects to oops.

01:21.940 --> 01:23.830
Objects to CSV.

01:25.060 --> 01:33.430
So objects to CSV is basically just converting these objects, JavaScript objects to a CSV file.

01:33.910 --> 01:36.490
And of course you could build this yourself.

01:36.490 --> 01:38.700
We could build it all the way from the ground up.

01:38.710 --> 01:42.700
Basically a CSV file is not that complicated.

01:43.750 --> 01:51.490
I mean, it's just columns with a separator like a comma between them and we could do that somehow for

01:51.490 --> 01:52.510
the JavaScript.

01:52.510 --> 01:58.180
But if someone already built it, why not just use their code instead if it works for you?

01:58.600 --> 02:00.370
So that's what we're going to do.

02:02.040 --> 02:02.820
First.

02:02.820 --> 02:05.280
Let's go and get the.

02:07.270 --> 02:07.980
Package.

02:07.990 --> 02:09.820
It's called objects to CSV.

02:09.850 --> 02:13.120
So we say yarn add objects to CSV.

02:15.240 --> 02:22.590
Then let's go and check out what he's writing in here so you can create the objects to csv file here.

02:24.070 --> 02:28.240
And then we can make an async call to create the CSV file.

02:28.240 --> 02:29.140
It's super easy.

02:29.140 --> 02:31.000
You just use the data and pass it in.

02:32.740 --> 02:40.570
I'm going to link to the objects to CSV page here as well, of course, so we can follow along.

02:42.170 --> 02:49.820
So I copy paste this objects to CSV require up here in the in the top and.

02:51.300 --> 02:54.790
Well, then we will make a new async function.

02:54.810 --> 02:57.030
Everything is async these days.

02:58.530 --> 03:02.550
Create a CSV file and we pass in the data.

03:05.570 --> 03:13.550
And then let's just shamelessly copy this code we have from the page here.

03:15.680 --> 03:18.550
And so it's creating a new CC.

03:19.250 --> 03:20.720
It's basically a string.

03:20.720 --> 03:22.730
I'm guessing you're getting out of it.

03:23.180 --> 03:32.390
And from the objects to CSV that we imported up here and you put in the data, which is just this array

03:32.390 --> 03:33.470
of objects.

03:33.950 --> 03:44.120
And then we call a asynchronous function inside of CSV, which is called to Dex to disk, and we just

03:44.120 --> 03:47.770
put in our file name and we get the file.

03:47.780 --> 03:52.790
I'm, I'm not interested in having this console log here, so I'm just going to delete that.

03:52.790 --> 03:54.920
We can read the file afterwards.

03:55.550 --> 03:57.500
Let's try and do it.

03:58.610 --> 04:03.380
Await create CSV file jobs, fold data.

04:04.430 --> 04:04.880
Okay.

04:04.880 --> 04:13.850
So now we can say that the job is done, we can go home and let's write node index.

04:13.850 --> 04:18.390
Just index dot JS Let's see if it writes the file.

04:18.390 --> 04:20.550
It should be writing the file.

04:21.930 --> 04:22.680
Okay.

04:23.790 --> 04:24.540
Tada.

04:25.350 --> 04:34.440
So here we have the header of the csv file with the title and then there's a description and URL.

04:34.470 --> 04:36.900
There's everything that you would need.

04:37.260 --> 04:42.000
Let's try and see if Google sheets can read this.

04:46.730 --> 04:49.940
So I'm just going to upload the file.

04:52.010 --> 04:53.210
Which one is it?

04:54.840 --> 04:55.710
Let's see.

04:57.310 --> 04:58.150
It's this one.

04:59.070 --> 05:01.080
Here is the text CSV.

05:05.490 --> 05:10.740
I just want to see if Google sheets can read this file if it looks okay.

05:11.580 --> 05:14.220
So I say open with Google sheets.

05:21.850 --> 05:23.530
Yeah, it, um.

05:23.980 --> 05:25.360
It looks okay.

05:25.390 --> 05:27.400
We have the description here.

05:27.400 --> 05:30.970
It's a pretty big text, but it's okay.

05:30.970 --> 05:34.810
I think it's a interesting data to have.

05:34.930 --> 05:43.990
Then we have the title and all of the different jobs here and with the compensation address, so on.

05:45.590 --> 05:46.100
Yeah.

05:46.790 --> 05:51.680
Uh, one thing to note is it is that the date posted looks pretty odd.

05:51.860 --> 05:56.780
This is actually the epoch time of the.

05:57.560 --> 06:01.070
The date that we made before, which was a JavaScript object.

06:01.250 --> 06:07.880
So if we try and put it in here, this one is assuming that the timestamp is in milliseconds.

06:07.880 --> 06:12.240
So it's kind of a weird format that the date is in.

06:12.260 --> 06:15.410
Let's try and make it a bit more readable for the data.

06:18.720 --> 06:27.180
So if you're going index.js and instead of having this as a JavaScript date, let's try and just have

06:27.180 --> 06:33.660
it as the date time property from the page itself and let's just run it again and try and see how it

06:33.660 --> 06:35.820
looks inside Google sheets this time.

06:40.530 --> 06:42.240
Da da da da da.

06:43.750 --> 06:45.070
Let me delete this one.

06:47.350 --> 06:49.330
And I think this one is done now.

06:49.330 --> 06:50.230
It's done.

06:50.920 --> 06:53.830
I will upload the new file and check it out.

06:55.000 --> 06:56.730
Check it out now.

06:57.890 --> 06:58.780
Doot doot.

06:58.780 --> 07:00.390
Doot doot doot doot doot doot.

07:00.520 --> 07:02.920
Okay, let's see.

07:08.260 --> 07:13.840
And now we have a lot more readable format for the date, I think.

07:14.710 --> 07:15.550
So.

07:17.170 --> 07:18.100
That was it.

07:18.130 --> 07:19.030
Well, now what?

07:19.030 --> 07:20.960
What are we going to do with the rest of our time?

07:21.000 --> 07:21.760
I don't know.

07:22.390 --> 07:23.970
Uh, go home, relax.

07:23.980 --> 07:25.690
Because we already did our job now.

07:25.690 --> 07:31.180
Which is to convert the Json into an CSV file from the scrape.

07:32.200 --> 07:39.080
If you have any other things you want to know, then feel free to write me in the YouTube or on Udemy.

07:39.100 --> 07:40.750
Questions and Answers.

07:41.200 --> 07:44.800
I'm always curious to see what you would like to learn.

07:44.980 --> 07:45.820
See you.
