Okay.
So I got a question from someone who saw my previous video about the Craigslist scraper.
Um, this is from Shark Tank.
Me or how you pronounce it.
He asked for confessing his love to me.
He asked if I could make a video about going from the array to a CSV.
And of course, I will show you how to do that.
It's super easy.
Um, first.
You need to have the scraper project as we did in the last video.
If you haven't been following the video, then you need to get the project from here inside of the GitHub.
I will link the GitHub in the video description or as a Udemy resource for this lecture.
Um, then you get the project and you should end up with a project looking sort of like this.
Okay.
So we have.
We have this function down here for Scrape Craigslist.
And what we're going to use is something called objects to oops.
Objects to CSV.
So objects to CSV is basically just converting these objects, JavaScript objects to a CSV file.
And of course you could build this yourself.
We could build it all the way from the ground up.
Basically a CSV file is not that complicated.
I mean, it's just columns with a separator like a comma between them and we could do that somehow for
the JavaScript.
But if someone already built it, why not just use their code instead if it works for you?
So that's what we're going to do.
First.
Let's go and get the.
Package.
It's called objects to CSV.
So we say yarn add objects to CSV.
Then let's go and check out what he's writing in here so you can create the objects to csv file here.
And then we can make an async call to create the CSV file.
It's super easy.
You just use the data and pass it in.
I'm going to link to the objects to CSV page here as well, of course, so we can follow along.
So I copy paste this objects to CSV require up here in the in the top and.
Well, then we will make a new async function.
Everything is async these days.
Create a CSV file and we pass in the data.
And then let's just shamelessly copy this code we have from the page here.
And so it's creating a new CC.
It's basically a string.
I'm guessing you're getting out of it.
And from the objects to CSV that we imported up here and you put in the data, which is just this array
of objects.
And then we call a asynchronous function inside of CSV, which is called to Dex to disk, and we just
put in our file name and we get the file.
I'm, I'm not interested in having this console log here, so I'm just going to delete that.
We can read the file afterwards.
Let's try and do it.
Await create CSV file jobs, fold data.
Okay.
So now we can say that the job is done, we can go home and let's write node index.
Just index dot JS Let's see if it writes the file.
It should be writing the file.
Okay.
Tada.
So here we have the header of the csv file with the title and then there's a description and URL.
There's everything that you would need.
Let's try and see if Google sheets can read this.
So I'm just going to upload the file.
Which one is it?
Let's see.
It's this one.
Here is the text CSV.
I just want to see if Google sheets can read this file if it looks okay.
So I say open with Google sheets.
Yeah, it, um.
It looks okay.
We have the description here.
It's a pretty big text, but it's okay.
I think it's a interesting data to have.
Then we have the title and all of the different jobs here and with the compensation address, so on.
Yeah.
Uh, one thing to note is it is that the date posted looks pretty odd.
This is actually the epoch time of the.
The date that we made before, which was a JavaScript object.
So if we try and put it in here, this one is assuming that the timestamp is in milliseconds.
So it's kind of a weird format that the date is in.
Let's try and make it a bit more readable for the data.
So if you're going index.js and instead of having this as a JavaScript date, let's try and just have
it as the date time property from the page itself and let's just run it again and try and see how it
looks inside Google sheets this time.
Da da da da da.
Let me delete this one.
And I think this one is done now.
It's done.
I will upload the new file and check it out.
Check it out now.
Doot doot.
Doot doot doot doot doot doot.
Okay, let's see.
And now we have a lot more readable format for the date, I think.
So.
That was it.
Well, now what?
What are we going to do with the rest of our time?
I don't know.
Uh, go home, relax.
Because we already did our job now.
Which is to convert the Json into an CSV file from the scrape.
If you have any other things you want to know, then feel free to write me in the YouTube or on Udemy.
Questions and Answers.
I'm always curious to see what you would like to learn.
See you.