Skip to content

Commit b0dc29c

Browse files
committed
added shares
1 parent 18faacf commit b0dc29c

File tree

10 files changed

+180
-248
lines changed

10 files changed

+180
-248
lines changed

.gitignore

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
/node_modules/
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# next.js build output
63+
.next
64+
65+
.gitignore
66+
.idea/workspace.xml
67+
68+
/conf/
69+

PageSamples/FriendsList.html

+1-1
Large diffs are not rendered by default.

PageSamples/Likes.html

+1-24
Large diffs are not rendered by default.

lib/app.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
1818

1919
var testData = {
2020
video: '/ufi/reaction/profile/browser/fetch/?limit=10&total_count=351&ft_ent_identifier=281112199228679',
21+
likesFullUrl: 'ufi/reaction/profile/browser/?ft_ent_identifier=2027002237395095',
2122
post: 'netanyahu/photos/a.10151681566507076/10156096314307076',
22-
likes: '10156096314337076',
23+
likes: '2027002237395095',
2324
user: 'peter.huwel', //'moshe.dzanashvili' // 'michael.even.54' // MAYASR
2425
itemID: '366827403332071',
2526
userID: '550385403'
2627
};
2728

28-
async function getData(initUrl, functionName) {
29+
async function getData(initUrl, functionName, type) {
2930

3031
var info = {
3132
list: [],
@@ -34,8 +35,10 @@ async function getData(initUrl, functionName) {
3435
};
3536

3637
await _getURL2.default.loadURL(initUrl).then(function (data) {
38+
console.log('loading: ', initUrl);
39+
3740
if (data) {
38-
var tmp = _Parser2.default[functionName](data);
41+
var tmp = _Parser2.default[functionName](data, type);
3942
tmp.list.forEach(function (item) {
4043
return console.log(item);
4144
});
@@ -47,7 +50,7 @@ async function getData(initUrl, functionName) {
4750
}
4851

4952
if (info.nextItemsUrl) {
50-
getData(null, info.nextItemsUrl);
53+
getData(info.nextItemsUrl, functionName, type);
5154
} else {
5255
console.log('End of list');
5356
}
@@ -65,19 +68,19 @@ async function App() {
6568
* Sample functions to loop through some data types
6669
* */
6770

68-
async function getUsersFromID(postId, fullUrl) {
71+
async function getLikesFromID(postId, fullUrl) {
6972
var url = postId ? "browse/likes/?id=" + postId : fullUrl;
70-
getData(url, 'getUserLikesFromPost');
73+
getData(url, 'getListByType', 'userLikes');
7174
}
7275

7376
async function getSharesFromID(postId, fullUrl) {
7477
var url = postId ? "browse/shares/?id=" + postId : fullUrl;
75-
getData(url, 'getUserSharesFromPost');
78+
getData(url, 'getListByType', 'shares');
7679
}
7780

7881
async function getUserFrinds(userName, fullUrl) {
7982
var url = userName ? userName + '/friends' : fullUrl;
80-
getData(url, 'getFriendsListFromUser');
83+
getData(url, 'getListByType', 'userFriends');
8184
}
8285

8386
async function testPageLoad(url) {
@@ -86,10 +89,10 @@ async function App() {
8689
});
8790
}
8891

89-
// getUsersFromID(testData.user); // <<< Need fix
92+
// getUserFrinds(testData.user);
9093

91-
// getUsersFromID(null, testData.video);
92-
getSharesFromID(testData.itemID);
94+
getLikesFromID(null, testData.likesFullUrl);
95+
// getSharesFromID(testData.itemID);
9396
// testPageLoad('/story.php?story_fbid=2622896591058463&id=366827403332071');
9497

9598
// FB API samples

lib/modules/Parser.js

+9-62
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ var _cheerio2 = _interopRequireDefault(_cheerio);
66

77
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
88

9-
// var linkifyStr = require('linkifyjs/string');
10-
11-
129
module.exports = {
1310

1411
selectors: {
15-
userLikes: ['._55wp a:first-child strong', ' div:nth-child(2) > a:nth-child(1) a', 'h3.be a'],
12+
userLikes: ['._55wp a:first-child strong', ' div:nth-child(2) > a:nth-child(1) a', 'h3.be a', ' div div div div div a:nth-child(1)'],
1613
userFriends: [' td.v.s:nth-child(2) a.ce', ' td.v.s:nth-child(2) a.bn'],
1714
total: ['div.t > a.u.v:nth-child(1)', 'h3.ca.i'],
1815
shares: ['div.v div.y a:nth-child(1)'],
@@ -39,7 +36,7 @@ module.exports = {
3936
var delimiter = str.indexOf('profile.php?') > -1 ? '&' : '?';
4037
return str.indexOf(delimiter) ? str.substr(0, str.indexOf(delimiter)) : str;
4138
},
42-
getUserLikesFromPost: function getUserLikesFromPost(data) {
39+
getListByType: function getListByType(data, type) {
4340
var _this = this;
4441

4542
var reObj = {
@@ -51,68 +48,18 @@ module.exports = {
5148
var response = this.testSelector('total', data);
5249
reObj.total = response && response.length ? response.text().replace('All', '') : null;
5350

54-
var likes = this.testSelector('userLikes', data);
55-
if (likes && likes.length) {
56-
likes.each(function (i, e) {
51+
var tmp = this.testSelector(type, data);
52+
if (tmp && tmp.length) {
53+
tmp.each(function (i, e) {
5754
return reObj.list.push({
58-
name: e.children[0].data,
55+
name: _this.getHrefText(e),
5956
link: _this.stripUrl(e.attribs.href)
6057
});
6158
});
6259
}
63-
64-
return reObj;
65-
},
66-
getUserSharesFromPost: function getUserSharesFromPost(data) {
67-
var _this2 = this;
68-
69-
var reObj = {
70-
list: [],
71-
total: 0,
72-
nextItemsUrl: ''
73-
};
74-
reObj.nextItemsUrl = this.getNextUrl(data);
75-
var response = this.testSelector('total', data);
76-
reObj.total = response && response.length ? response.text().replace('All', '') : null;
77-
78-
var shares = this.testSelector('shares', data);
79-
if (shares && shares.length) {
80-
shares.each(function (i, e) {
81-
return reObj.list.push({
82-
name: e.children[0].children[0].data,
83-
link: _this2.stripUrl(e.attribs.href)
84-
});
85-
});
86-
}
87-
8860
return reObj;
8961
},
90-
getFriendsListFromUser: function getFriendsListFromUser(data) {
91-
var _this3 = this;
92-
93-
var reObj = {
94-
list: [],
95-
total: 0,
96-
nextItemsUrl: ''
97-
};
98-
99-
var $ = _cheerio2.default.load(data); // , {decodeEntities: false}
100-
101-
reObj.total = $(this.selectors.total).text().replace('Friends (', '').replace(')', '');
102-
103-
reObj.nextItemsUrl = this.getNextUrl(data);
104-
105-
var list = testSelector('userFriends', data);
106-
107-
if (list) {
108-
list.each(function (i, e) {
109-
return reObj.list.push({
110-
name: $(e).text(),
111-
link: _this3.stripUrl($(e).attr('href'))
112-
});
113-
});
114-
}
115-
116-
return reObj;
62+
getHrefText: function getHrefText(e) {
63+
return e.children && e.children[0].children ? e.children[0].children[0].data : e.children[0].data;
11764
}
118-
};
65+
};

lib/modules/getURL.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ var _puppeteer = require('puppeteer');
44

55
var _puppeteer2 = _interopRequireDefault(_puppeteer);
66

7+
var _conf = require('../../conf/conf');
8+
79
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
810

911
// settings
1012
var baseurl = 'http://m.facebook.com/';
1113

12-
var cookie = 'fr=0KgX4GMptclnHZ9qh.AWV0dX2f30k9_H1aQe1L2GP9xKE.Bax3uv.RT.Fw8.0.0.BcP7WB.AWXVxiku; sb=_J8CW4AQlTIzFC8dv0vndc0s; datr=_J8CW6NvLHqAPlgT8HSFslLj; c_user=100000913008569; xs=19%3ALRZbkGRGwty5Cg%3A2%3A1526898806%3A20786%3A15166; act=1547594911305%2F17; wd=1296x644; dpr=2; presence=EDvF3EtimeF1547594591EuserFA21B00913008569A2EstateFDt3F_5b_5dEutc3F1541075385853G547594591587CEchFDp_5f1B00913008569F2CC';
13-
14-
var userAgent = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
15-
1614
module.exports = {
1715
loadURL: async function loadURL(url) {
1816
var fullurl = baseurl + url;
1917

2018
var browser = await _puppeteer2.default.launch({ headless: true });
2119
var page = await browser.newPage();
2220
await page.setRequestInterception(true);
23-
await page.setUserAgent(userAgent);
21+
await page.setUserAgent(_conf.userAgent);
2422

2523
try {
2624

@@ -40,7 +38,7 @@ module.exports = {
4038
var headers = request.headers();
4139
headers['Access-Control-Allow-Origin'] = '*';
4240

43-
headers['Cookie'] = cookie;
41+
headers['Cookie'] = _conf.cookie;
4442

4543
request.continue({ headers: headers });
4644
});
@@ -54,9 +52,9 @@ module.exports = {
5452
if (response._status < 400) {
5553
// await page.waitFor('#m_more_friends a');
5654

57-
// await page.waitForNavigation( { waitUntil : 'networkidle0' } );
58-
59-
console.log('Loading page');
55+
console.log('Loading page: ', fullurl);
56+
// await page.waitForNavigation( { waitUntil : 'networkidle2' } );
57+
await page.waitFor(2000);
6058
var html = await page.content();
6159

6260
await browser.close();

0 commit comments

Comments
 (0)