Reputation: 473
I am trying to make a Web Scraper using Javascript. I need to extract the number 1214 from this Element: -
<span class="ss-icon-user num-students left">
1,214
</span>
Now I have written this code for it :-
var students = $('.ss-icon-user num-students left');
var no_of_students = students.text();
console.log(no_of_students);
but it gives no output at all. I tried :-
console.log(no_of_students.length);
and it gives the output 0.
Can anyone tell me why am I unable to extract it? What changes do I have to make?
Upvotes: 0
Views: 47
Reputation: 9
Try to do this:
$('.ss-icon-user.num-students.left').html();
You need to put dot "." in every class inside your tag.
Upvotes: 1
Reputation: 1736
Your selector is wrong. The span has 3 different classes - ss-icon-user, num-students, and left. Your selector is looking for elements with the ss-icon-user class which have a child "num-students" TAG with in turn has a child "left" TAG. If you want to select multiple classes, you would do it like this:
var students = $('.ss-icon-user, .num-students, .left');
Note that this could potentially pull back multiple entries if more than one element has all three of these classes.
Upvotes: 1