-
Notifications
You must be signed in to change notification settings - Fork 2
/
Crunchbase.user.js
139 lines (111 loc) · 5.43 KB
/
Crunchbase.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
// ==UserScript==
// @name Crunchbase
// @namespace crunchbase.script
// @version 0.1
// @description Scrape pubic data from crunchbase
// @author Kowshika
// @match https://crunchbase.com/*
// @match https://www.crunchbase.com/*
// @runat document-end
// @grant none
// ==/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() {
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();
waitForElementToDisplay('.profile-name', 5000);
waitForElementToDisplay('page-footer', 5000);
waitForElementToDisplay('anchored-values', 5000);
if (has(window.location.href, 'organization')){
var company_name = document.getElementByXPath('//*[@class="profile-name"]').textContent.trim()
var company_url = ""
var headquarters = ""
var Sector = ""
var type = ""
var symbol = ""
var funding= ""
var amount = ""
var phone = ""
if (document.getElementByXPath('(//a[@role="link"])[1]') != null) {
company_url = document.getElementByXPath('(//a[@role="link"])[1]').getAttribute('href');
}
if (document.getElementByXPath("//a[contains(@href, '/field/organizations/location_identifiers')]") != null) {
headquarters = document.getElementByXPath("(//a[contains(@href, '/field/organizations/location_identifiers')])//..//..//span").textContent;
}
if (document.getElementByXPath("//mat-chip") != null) {
var count = document.getElementsByXPath("//mat-chip").length;
for (var i=1; i <= count; i ++){
Sector += document.getElementByXPath("(//mat-chip)[" + i.toString() + "]").textContent + ", ";
}
Sector = Sector.replace(/,\s*$/, "");
}
if (document.getElementByXPath("//*[@title='Public']") != null){
type = "Public"
} else {
type = "Private"
}
waitForElementToDisplayWithXpath("//*[text() = 'Stock ']//..//..//..//a | //*[text() = 'Stock Symbol']//..//..//..//blob-formatter/span", 2000);
if (document.getElementByXPath("//*[text() = 'Stock ']//..//..//..//a | //*[text() = 'Stock Symbol']//..//..//..//blob-formatter/span") != null){
symbol = document.getElementByXPath("//*[text() = 'Stock ']//..//..//..//a | //*[text() = 'Stock Symbol']//..//..//..//blob-formatter/span").textContent.trim();
}
if (document.getElementByXPath("//span[text()='Phone Number']//..//..//..//blob-formatter/span") != null){
phone = document.getElementByXPath("(//span[text()='Phone Number']//..//..//..//span)[last()]").textContent.trim()
}
if (document.getElementByXPath("(//a[contains(@href, 'organizations/last_funding_type')])[1]") != null){
funding = document.getElementByXPath("(//a[contains(@href, 'organizations/last_funding_type')])[1]").textContent.trim()
}
if (document.getElementByXPath("(//span[contains(@class, 'field-type-money')])[1]") != null){
amount = document.getElementByXPath("(//span[contains(@class, 'field-type-money')])[1]").textContent.trim()
}
textData += headquarters + " | "
textData += Sector + " | "
textData += type + " | "
textData += symbol + " | "
textData += funding + " | "
textData += amount + " | "
textData += company_name + " | "
textData += company_url + " | "
textData += window.location.href + " | "
textData += phone
if (textData.length > 10){
saveText("listingData.txt", textData);
} else {
console.log('No Data found.')
}
}
console.log('Page loaded');
})();