WEBVTT

00:01.020 --> 00:06.990
As you can see in our console log, we do get all of the job descriptions, but we are only outputting

00:06.990 --> 00:10.050
the job descriptions in our console log so far.

00:10.080 --> 00:12.000
We're not saving it in our object.

00:12.000 --> 00:14.340
Let's try and do that now in this section.

00:14.910 --> 00:20.430
Let's save the description on a job dot description property.

00:20.430 --> 00:25.290
And then let's see what this new array looks like when it's returned from the map function.

00:25.590 --> 00:27.420
So that looks something like this.

00:27.420 --> 00:32.580
We're just going to say job description equals description.

00:32.580 --> 00:36.510
And let's return this job that's been modified a little bit.

00:37.410 --> 00:46.350
Let's say jobs let's call it all jobs with descriptions that's returned from this all jobs dot map.

00:47.110 --> 00:54.190
And after that, let me just, uh, silence this console log for a bit, and let's try and do a console

00:54.190 --> 00:59.710
log of the all jobs with descriptions at the end of this function.

01:00.900 --> 01:04.350
Let's do a node index.js and see what this looks like.

01:06.010 --> 01:06.400
Huh.

01:06.400 --> 01:13.660
So okay, so you can see here that we do get a lot of promises that's been pending or is pending.

01:13.660 --> 01:17.140
Now when we did the console log inside here in the function.

01:17.140 --> 01:19.930
Well it just prints out the description once.

01:19.930 --> 01:22.540
This promise up here has been resolved.

01:22.750 --> 01:29.920
But when we do use map here, uh, with the async call, well, it just returns all of these promises

01:29.920 --> 01:36.070
that's pending, but it's quite easy to get around that we can just say something like, let's call

01:36.070 --> 01:36.790
this.

01:38.590 --> 01:40.750
With promises instead.

01:41.740 --> 01:44.380
Or let's call it, just promises.

01:45.160 --> 01:46.120
It's shorter.

01:46.120 --> 01:57.430
And then let's say, uh, let's say we can say all job descriptions and then we can say await promise,

01:57.430 --> 01:58.780
dot all.

01:58.780 --> 02:02.500
And we pass in the all job descriptions promises here.

02:02.500 --> 02:07.300
And then we can do a console log of all job descriptions.

02:12.380 --> 02:17.150
Let's do a node index.js and see what this looks like.

02:19.370 --> 02:20.330
So there we go.

02:20.330 --> 02:27.620
Now we can see we get these nice objects here, which has the title, the URL and the description,

02:27.620 --> 02:28.760
which is really great.

02:28.760 --> 02:34.160
If you want to save it in a database like MongoDB, you can even save it in a relational database as

02:34.160 --> 02:35.540
well if you want to do that.

02:36.350 --> 02:45.260
But one thing to keep in mind though, is when we use this dot map function, the excuse is firing all

02:45.260 --> 02:48.950
these 325 requests all at once.

02:49.190 --> 02:58.460
So this is very fast, but you're also quite prone to be blocked from a website if you use this method,

02:58.460 --> 03:03.500
because you fire off so many requests at once, you're firing off.

03:03.500 --> 03:03.890
Um.

03:05.570 --> 03:07.700
All requests at once.

03:09.350 --> 03:15.710
So that's very prone to getting you blocked from a website because, for example, with the actual Craigslist

03:15.710 --> 03:22.310
website, if you do this, you're going to get blocked from or banned from the website for 24 hours,

03:22.310 --> 03:23.180
basically.

03:23.420 --> 03:29.870
So there is a method to get around this and scrape not so aggressively and avoid getting blocked.

03:29.870 --> 03:33.080
And that's what I'm going to show you in the next section.
