-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloopFacebookGroups
38 lines (37 loc) · 1.63 KB
/
loopFacebookGroups
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const Nightmare = require('nightmare'),
nightmare = Nightmare();
module.exports = {
loopFacebookGroups: function (groups) {
for (var i = 0; groups.length > i; i++) {
var post = yield nightmare.goto(groups[i])
.wait(200) // I like to wait tiny bit before injecting jQuery
.inject('js', './node_modules/jquery/dist/jquery.js') // injecting jQuery into the page
.wait(3000)
.evaluate(() => {
var posts = [];
$('._5pcr').each(function (index) {
var post = {};
var userName = $(this).find('h5 a').text();
var price = $(this).find('._l57').text();
var postDate = $(this).find('abbr').attr('title');
var postTitle = $(this).find('._l53>span:last-child').text();
var location = $(this).find('.mtm ._l58').text();
var description = $(this).find('.userContent p').text();
post.id = index;
post.price = price;
post.username = userName;
post.date = postDate;
post.title = postTitle;
post.location = location;
post.description = description;
posts.push(post);
})
return posts;
})
.then(function (posts) {
console.log(posts);
postData = posts;
})
}
}
}