-
Notifications
You must be signed in to change notification settings - Fork 2
/
Daycare_Data.user.js
148 lines (127 loc) · 6.09 KB
/
Daycare_Data.user.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// ==UserScript==
// @name GA Daycares data
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Scrape daycare info
// @author Kowshika N
// @match https://families.decal.ga.gov/ChildCare/detail/*
// @match http://families.decal.ga.gov/ChildCare/detail/*
// @include https://families.decal.ga.gov/ChildCare/detail/*
// @include http://families.decal.ga.gov/ChildCare/detail/*
// @include https://families.decal.ga.gov/ChildCare/Results*
// @match https://families.decal.ga.gov/ChildCare/Results*
// @grant none
// @runat document-end
// ==/UserScript==
function has(String, search) { try { if (String.indexOf(search) > -1) { return true; } } catch (err) {} return false; }
function waitForElementToDisplay(selector, time) {
if(document.querySelector(selector) != null) {
console.log(selector + ' found');
return;
}
else {
setTimeout(function() {
waitForElementToDisplay(selector, time);
}, time);
}
}
function waitForElementToDisplayWithXpath(xpath, time) {
document.getElementByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (a.snapshotLength > 0) { return a.snapshotItem(0); } };
if(document.getElementByXPath(xpath) != null) {
console.log(xpath + ' found');
return;
}
else {
setTimeout(function() {
waitForElementToDisplayWithXpath(xpath, time);
}, time);
}
}
(function() {
'use strict';
var textData = "";
function saveText(filename, text) {
var tempElem = document.createElement('a');
tempElem.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
tempElem.setAttribute('download', filename);
tempElem.click();
console.log(filename + ' File downloaded');
}
function sleep(ms) { return new Promise(res => setTimeout(res, ms)); };
let sleepFunc = async function() { await sleep(3000); };
document.getElementByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (a.snapshotLength > 0) { return a.snapshotItem(0); } };
document.getElementsByXPath = function(sValue){ var aResult = new Array();var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);for ( var i = 0 ; i < a.snapshotLength ; i++ ){aResult.push(a.snapshotItem(i));}return aResult;};
sleepFunc();
function getText(xpath){
var text = ""
if (document.getElementByXPath(xpath) != null){ text = document.getElementByXPath(xpath).textContent }
return text
}
document.onreadystatechange = function () {
if (document.readyState == "complete") {
waitForElementToDisplay('#Content_Main_lblFacilityName', 5000);
waitForElementToDisplay('#Content_Main_imgPreK', 5000);
if (has(window.location.href, '/Results')){
function keeploading(){
document.getElementById('pnlLoadMore').scrollIntoView();
document.getElementById('pnlLoadMore').click();
}
function heavyWork(){
for (var i=0; i<10; i++){
console.log(i);
var interval = setInterval((function(x){
return function(){
keeploading();
};
})(i), 5000);
if (document.getElementById('pnlLoadMore').style.display == "none"){
window.clearInterval(interval);
}
}
}
//heavyWork();
waitForElementToDisplayWithXpath("//a[contains(@href, 'detail/')]", 10000)
document.getElementById('pnlSortBy').scrollIntoView();
var count = document.getElementsByXPath("//a[contains(@href, 'detail/')]").length;
for (var i=1; i <= count; i++){
textData += document.getElementByXPath("(//a[contains(@href, 'detail/')])["+ i.toString()+ "]").href + "\n"
}
if (textData.length > 40){
saveText("listingLinks.txt", textData);
} else {
console.log('No Data found.')
}
}
if (has(window.location.href, '/detail/')){
var DaycareName = getText("//*[contains(@id, 'FacilityName')]")
var Address = getText("//address").replace(/(?:\r\n|\r|\n|\s\s)/g, ' ').replace(/\s+/g, ' ').replace('Get Directions', '').trim()
var ContactName = getText("//*[contains(@id, 'Admin')]")
var PhoneNumber = getText("//*[contains(@id, 'Phone')]")
var Website = ""
if (document.getElementByXPath("//*[contains(@id, 'Website')]//a") != null) {
Website = document.getElementByXPath("//*[contains(@id, 'Website')]//a").href
}
var Facebook = ""
if (document.getElementByXPath("//*[contains(@id, 'Facebook')]") != null) {
Facebook = document.getElementByXPath("//*[contains(@id, 'Facebook')]").href
}
var Type = getText("//*[contains(@id, 'ProgramType')]")
var Capacity = getText("//*[contains(@id, 'lblCapacity')]")
textData += DaycareName + " | "
textData += Address + " | "
textData += ContactName + " | "
textData += PhoneNumber + " | "
textData += Website + " | "
textData += Facebook + " | "
textData += Type + " | "
textData += Capacity + " | "
textData += window.location.href + " | "
if (textData.length > 80){
saveText("listingData.txt", textData);
} else {
console.log('No Data found.')
}
}
}
}
})();