Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filtering by title + minor improvements #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
config.json
.idea
NepremicnineProd.json
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{

"name": "real-estate-scraper",
"version": "0.0.1",
"description": "Realestate scraper",
"repository": {
"type": "git"
},

"dependencies": {
"nodemailer": "2.4.2",
"tinyreq": "3.1.1",
"node-json-db": "0.7.2",
"cheerio": "0.20.0",
"daemon": "1.1.0"
}

}
83 changes: 53 additions & 30 deletions scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ sites.push({
conn: "www.bolha.com" + bAds[i].children[3].children[1].children[0].attribs.href,
price: bAds[i].children[7].children[1].children[0].children[0].data
};
try {
db.getData("/B"+ad.id);
} catch (err){
bolhaDelta += 1;
db.push("/B"+ad.id,ad);
delta.push(ad);
}

if (processFilters(ad)) {
try {
db.getData("/N"+ad.id);
} catch (err){
bolhaDelta += 1;
db.push("/N"+ad.id,ad);
delta.push(ad);
}
}
}
}
console.log((new Date()).toString() + " BOLHA.COM Delta: " + bolhaDelta);
Expand All @@ -100,12 +103,15 @@ sites.push({
conn: "https://www.nepremicnine.net" + nAds[i].children[5].children[5].children[0].attribs.href,//nAds[i].children[1].children[0].attribs.href,
price: nAds[i].children[5].children[11].children[13].children[4].children[0].data//nAds[i].children[5].children[13].children[4].children[0].data
};
try {
db.getData("/N"+ad.id);
} catch (err){
nepremDelta += 1;
db.push("/N"+ad.id,ad);
delta.push(ad);

if (processFilters(ad)) {
try {
db.getData("/N"+ad.id);
} catch (err){
nepremDelta += 1;
db.push("/N"+ad.id,ad);
delta.push(ad);
}
}
}
}
Expand All @@ -115,24 +121,41 @@ sites.push({
}
});

function processFilters(ad) {
var filters = config.filters;
var titleContains = filters.title.contains;

if (titleContains.length > 0) {
for(var i in titleContains) {
if (ad.title.indexOf(titleContains[i]) !== -1) {
return true;
}
}
} else {
return true;
}

setInterval(
function(){
console.log((new Date()).toString() + " STARTED");
if ((new Date()).getHours() < 22 && (new Date()).getHours() >= 7) {
for (var i = 0; i < sites.length; i++){
request({
url: sites[i].url,
method: "GET",
headers: {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
}
},
sites[i].callback
);
}
}
},
return false;
}

function runScraping() {
console.log((new Date()).toString() + " STARTED");
if ((new Date()).getHours() < 22 && (new Date()).getHours() >= 7) {
for (var i = 0; i < sites.length; i++){
request({
url: sites[i].url,
method: "GET",
headers: {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
}
},
sites[i].callback
);
}
}
}

setInterval(
runScraping,
interval * 60 * 1000
);