-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapeYellowPages.js
89 lines (82 loc) · 2.5 KB
/
scrapeYellowPages.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
const scrapeIt = require("scrape-it");
const fs = require("fs");
async function scraPeYellowPages(name, location, vertical) {
filteredName = name.replace(/\s/g, "+");
filteredLocation = location.replace(/\s/g, "+");
let query = `https://www.yellowpages.com/search?search_terms=${filteredName +
"+" +
vertical}&geo_location_terms=${filteredLocation}`;
// console.log(query);
return await scrapeIt(query, {
articles: {
listItem: ".result",
data: {
title: "a.business-name",
website: {
selector: ".links > a",
attr: "href"
},
link: {
selector: ".business-name",
attr: "href",
convert: item => `https://www.yellowpages.com${item}`
},
address: ".street-address"
}
}
})
.then(async res => {
if (res) {
let data = res.data;
// console.log("DATA", data.articles);
if (data.articles) {
if (data.articles.length > 0) {
// console.log("datalink", data.articles[0].link);
if (data.articles[3].link) {
let linkProfile = data.articles[3].link;
console.log("Company Info", data.articles[3]);
let companyInfo = data.articles[3];
let email = await scrapeEmailFromYellowP(linkProfile);
// console.log(
// "YELLOW PAGES EMAIL",
// email,
// "COMPANY INFO",
// companyInfo
// );
return { email, companyInfo };
}
}
}
} else {
return {};
}
})
.catch(err => {});
}
async function scrapeEmailFromYellowP(link) {
return await scrapeIt(link, {
email: {
selector: ".email-business",
attr: "href"
}
})
.then(resp => {
if (resp != undefined) {
let data = resp.data;
let emailData = data.email.replace("mailto:", "");
if (emailData) {
// console.log("EMAIL :", emailData);
return emailData;
}
} else {
return [];
}
})
.catch(err => []);
}
// (CEO || Owner) + (at || of )
// let snippet =
// "Taylor Pierce Apps LLC January 2009 – May 2012 (3 years 5 months) Austin, Texas Taylor Pierce Apps developed the Virtual Coach iPhone App series that had over 300,000 paid downloads in only two years.";
// console.log(snippet);
//scraPeYellowPages("Flynn Construction", "Texas", "Building");
module.exports.scraPeYellowPages = scraPeYellowPages;