-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
93 lines (68 loc) · 2.09 KB
/
inject.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var db = [];
var myInfinity = 10000000000;
function getUsers () {
var user;
if (document.URL.substring(0,32) == "https://www.facebook.com/hashtag")
{
user = document.evaluate("//span[@class='fwb fcg']/a", document, null, XPathResult.ANY_TYPE, null);
}
else if (document.URL.substring(0,26) == "https://twitter.com/search")
{
user = document.evaluate("//span[@class='username js-action-profile-name']/b", document, null, XPathResult.ANY_TYPE, null);
}
var iterator = user.iterateNext();
var users = [];
while(iterator) {
users.push(iterator.textContent);
iterator = user.iterateNext();
}
return users;
}
function getTfbs() {
var tfb = document.evaluate("//p[@class='js-tweet-text tweet-text']", document, null, XPathResult.ANY_TYPE, null);
var tfb;
if (document.URL.substring(0,32) == "https://www.facebook.com/hashtag")
{
tfb = document.evaluate("//div[@class='_5pbx userContent']", document, null, XPathResult.ANY_TYPE, null);
}
else if (document.URL.substring(0,26) == "https://twitter.com/search")
{
tfb = document.evaluate("//p[@class='js-tweet-text tweet-text']", document, null, XPathResult.ANY_TYPE, null);
}
var iterator = tfb.iterateNext();
var tfbs = [];
while (iterator) {
tfbs.push(iterator.textContent);
iterator = tfb.iterateNext();
}
return tfbs;
}
function tfbsCounter() {
var tfbs = getTfbs();
var tfbsLength = tfbs.length;
return tfbsLength;
}
function startScraping(tfbsAmount) {
var tfbs = getTfbs();
var users = getUsers();
var tfbsLength = tfbs.length;
for(var i = 0; i <= tfbsAmount - 1; i++) {
var item = {"User": users[i], "Mensaje": tfbs[i]};
db.push(item);
};
var json_text = JSON.stringify(db, null, 2);
console.log(json_text);
}
function scrollBottom(tfbsAmount) {
setTimeout(function timeOut() {
var tfbsLength = tfbsCounter();
document.body.scrollTop = myInfinity;
if (tfbsLength < tfbsAmount) {
scrollBottom(tfbsAmount);
}
else {
startScraping(tfbsAmount);
}
}, 100);
}
scrollBottom(10);