WEBVTT

00:00.650 --> 00:06.080
Now, one more thing I want to show you before we move on to our first real world scraper, where we

00:06.080 --> 00:07.700
scrape Craigslist site.

00:08.030 --> 00:14.720
I'm going to show you one more thing you can use to select elements inside jQuery, and that is attributes.

00:14.930 --> 00:21.350
So if we select this element here, we can see that it has an attribute saying data customer with the

00:21.350 --> 00:22.700
customer number here.

00:23.970 --> 00:28.620
And let's imagine that we have well, we have these two H1 classes.

00:28.620 --> 00:31.240
They both have the class of red.

00:31.260 --> 00:38.880
So if you only wanted the last element here, the only way to select it is by taking in this attribute

00:38.880 --> 00:39.570
as well.

00:40.470 --> 00:42.750
So let's see how we can do that.

00:42.750 --> 00:47.730
You can simply double click on this attribute here and say, Copy.

00:49.220 --> 00:52.190
Then you can first inject jQuery.

00:53.780 --> 01:04.220
And then put a dollar sign and then use single quotes instead and a square bracket first and then end

01:04.220 --> 01:10.910
it with a square bracket and then end it with a single quote and then put in the text.

01:11.360 --> 01:15.710
So now we are selecting an element with this attribute instead.

01:18.470 --> 01:23.150
And notice we had to use single quotes because we had double quotes in here.

01:23.270 --> 01:31.280
You could also switch switch it around so that you have double quotes here and single quotes in here.

01:31.580 --> 01:35.840
As long as you are, as long as you are consistent about it.

01:37.120 --> 01:40.390
So that's how you select elements with an attribute.

01:42.230 --> 01:47.450
If you don't want to make it for an attribute with a particular value like this one and you just want

01:47.450 --> 01:55.550
to select all elements with this attribute, you can simply say dollar sign and say data customer.

01:57.300 --> 01:59.940
And then say that text.

02:00.120 --> 02:07.950
So now we select all the elements with this attribute and not just the ones with the specific value.

02:08.070 --> 02:14.310
So now I think it's been enough practice on my little local sites and I think we should try and have

02:14.310 --> 02:18.810
fun with the actual real world site such as Craigslist.

02:19.560 --> 02:23.910
So I'll see you in the next sections and I hope you have lots of fun with this.
