-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFBscrapers.js
64 lines (62 loc) · 2.9 KB
/
FBscrapers.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const Credentials = require('./credentialss'), // Include our credentials
Nightmare = require('nightmare'),
vo = require('vo'),
nightmare = Nightmare({show: true}),
domain = 'https://facebook.com', // Initial navigation domain
groups = ['https://www.facebook.com/groups/394556737385005/?sorting_setting=RECENT_ACTIVITY', // Scrapable group array
'https://www.facebook.com/groups/391908637633014/?sorting_setting=RECENT_ACTIVITY'];
// add console logging - makes life a bit easier
nightmare
.on('console', (log, msg) => {
console.log(msg);
console.log(Credentials.facebook_username);
})
.useragent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36") // browser info - not essential
.goto(domain)
.type('input[id="email"]', Credentials.facebook_username)
.type('input[id="pass"]', Credentials.facebook_password)
.click('#loginbutton>input')
.wait(3000) // will wait 3 seconds to load next page
.then(() => {
var run = function* () {
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;
})
}
}
// setInterval(() => {
vo(run)((res) => {
console.log(res);
})
// }, 1800000)
})
.catch((error) => {
console.error('Something went wrong:', error)
});