Skip to content

Commit

Permalink
v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mallendeo committed May 16, 2019
1 parent c7b64b2 commit 23b0408
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
import got from 'got';
export declare const txt: (el: Cheerio) => string;
export declare const dom: (url: got.GotUrl, opts?: got.GotOptions<any>) => Promise<CheerioStatic>;
export declare const parseDate: (str: string) => Date;
19 changes: 19 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const got_1 = __importDefault(require("got"));
const cheerio_1 = __importDefault(require("cheerio"));
const MONTHS = [
'enero',
'febrero',
'marzo',
'abril',
'mayo',
'junio',
'julio',
'agosto',
'septiembre',
'octubre',
'noviembre',
'diciembre',
];
exports.txt = (el) => el.text().trim();
exports.dom = (url, opts) => __awaiter(this, void 0, void 0, function* () {
const { body } = yield got_1.default(url, opts);
return cheerio_1.default.load(body);
});
exports.parseDate = (str) => {
const [date, month, year] = str.toLowerCase().split(' de ');
const monthIndex = MONTHS.indexOf(month);
return new Date(+year, monthIndex, +date);
};
7 changes: 5 additions & 2 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import got from 'got';
declare const _default: (session?: string, defaultOpts?: got.GotOptions<any>) => Promise<{
declare const GetOnBrd: (session?: string, defaultOpts?: got.GotOptions<any>) => Promise<{
getCompanyProfile: (url: string, gotOpts?: got.GotOptions<any>) => Promise<{
title: string;
logo: string;
Expand All @@ -17,6 +17,7 @@ declare const _default: (session?: string, defaultOpts?: got.GotOptions<any>) =>
}>;
getJob: (url: string, gotOpts?: got.GotOptions<any>) => Promise<{
date: string;
parsedDate: Date;
salary: number[];
company: {
logo: string;
Expand All @@ -36,6 +37,8 @@ declare const _default: (session?: string, defaultOpts?: got.GotOptions<any>) =>
country: string;
city: string;
}>;
getCategories: (gotOpts?: got.GotOptions<any>) => Promise<any[]>;
getJobsFromCategory: (categoryUrl: string, gotOpts?: got.GotOptions<any>) => Promise<any[]>;
_csrfToken: string;
}>;
export default _default;
export default GetOnBrd;
27 changes: 24 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const qs_1 = __importDefault(require("qs"));
const sanitize_html_1 = __importDefault(require("sanitize-html"));
const helpers_1 = require("./helpers");
const HOST = 'https://www.getonbrd.com';
const HOST_CL = 'https://www.getonbrd.cl';
const SEARCH_URL = `${HOST}/webpros/search_jobs`;
const DEFAULT_HEADERS = {
'accept-language': 'es-US,es;q=0.9,es-419;q=0.8,en;q=0.7',
Expand All @@ -38,9 +39,9 @@ const getContent = (el, excludedTags = ['div']) => {
return sanitize_html_1.default(descHtml, {
allowedTags,
allowedIframeHostnames: ['www.youtube.com'],
});
}).trim();
};
exports.default = (session, defaultOpts = {}) => __awaiter(this, void 0, void 0, function* () {
const GetOnBrd = (session, defaultOpts = {}) => __awaiter(this, void 0, void 0, function* () {
const sessionCookie = `_getonboard_session=${session};`;
let csrfToken = '';
if (session) {
Expand Down Expand Up @@ -87,8 +88,10 @@ exports.default = (session, defaultOpts = {}) => __awaiter(this, void 0, void 0,
.map(n => n.match(/\d+/g).join(''))
.map(Number)
: null;
const date = helpers_1.txt(_company.find('time'));
return {
date: helpers_1.txt(_company.find('time')),
date,
parsedDate: helpers_1.parseDate(date),
salary,
company: {
logo: _company.find('.gb-company-logo__img').attr('src'),
Expand Down Expand Up @@ -130,6 +133,21 @@ exports.default = (session, defaultOpts = {}) => __awaiter(this, void 0, void 0,
links,
};
});
const getCategories = (gotOpts = defaultOpts) => __awaiter(this, void 0, void 0, function* () {
const $ = yield helpers_1.dom(HOST_CL, gotOpts);
return $('.bg-white a[href^="/emp"]')
.map((i, el) => HOST + $(el).attr('href'))
.get();
});
const getJobsFromCategory = (categoryUrl, gotOpts = defaultOpts) => __awaiter(this, void 0, void 0, function* () {
const $ = yield helpers_1.dom(categoryUrl, gotOpts);
return $('.job')
.map((i, el) => $(el)
.find('a')
.first()
.attr('href'))
.get();
});
return {
getCompanyProfile,
getJobsBySalary: (...args) => __awaiter(this, void 0, void 0, function* () {
Expand All @@ -138,6 +156,9 @@ exports.default = (session, defaultOpts = {}) => __awaiter(this, void 0, void 0,
return getJobsBySalary(...args);
}),
getJob,
getCategories,
getJobsFromCategory,
_csrfToken: csrfToken,
};
});
exports.default = GetOnBrd;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@chile-sh/getonbrd-scraper",
"types": "lib/index.d.ts",
"main": "lib/index.js",
"version": "3.0.1",
"version": "3.0.2",
"repository": "[email protected]:chile-sh/getonbrd-scraper.git",
"author": "mallendeo",
"license": "MIT",
Expand Down

0 comments on commit 23b0408

Please sign in to comment.