-
Notifications
You must be signed in to change notification settings - Fork 2
/
Realtor_Details.user.js
77 lines (62 loc) · 2.85 KB
/
Realtor_Details.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
// ==UserScript==
// @name realtor details
// @namespace http://tampermonkey.net/
// @description Scrape data from realtor site
// @version 0.1
// @author kowshika-n
// @homepage https://github.com/kowshika1
// @downloadURL https://github.com/kowshika1/WebScraping_Userscripts/raw/master/realtor_details.user.js
// @updateURL https://github.com/kowshika1/WebScraping_Userscripts/raw/master/realtor_details.user.js
// @include https://www.google.com/url?sa*
// @include https://www.realtor.com/realestateandhomes-detail*
// @include https://www.realtor.com/realestateandhomes-detail/*
// @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);
}
}
(async function() {
'use strict';
var textData = "";
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); } };
sleepFunc();
document.onreadystatechange = function () {
if (document.readyState == "complete") {
waitForElementToDisplay('.business-card-content', 3000);
waitForElementToDisplay('.business-card-broker', 3000);
}
}
console.log('Page loaded');
if (has(window.location.href, 'google.')){
document.getElementByXPath("//a[1]").click();
}
if (document.getElementsByClassName('.business-card-broker').length >= 1){document.getElementsByClassName('.business-card-broker')[0].scrollIntoView(false)};
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');
}
textData = window.location.href.split("?ex=")[0] + " | "
textData += document.getElementByXPath("//*[contains(@class,'business-card-agent')]").textContent.replace(/\n/g, " ").trim()
textData += " | "
textData += document.getElementByXPath("//*[contains(@class,'business-card-broker')]").textContent.replace(/\n/g, " ").trim();
if (textData.length > 50){
saveText("realestateandhomes-detail.txt", textData);
} else {
console.log('No Data found.')
}
})();