Skip to content

Commit

Permalink
fixed Smithfield scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalaurentiu committed Oct 21, 2023
1 parent f97321f commit 097d876
Showing 1 changed file with 54 additions and 44 deletions.
98 changes: 54 additions & 44 deletions sites/smithfield.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
"use strict";
const scraper = require("../peviitor_scraper.js");
const uuid = require("uuid");

let url = "https://www.smithfield.ro/ro/cariere/posturi-disponibile";

const company = { company: "Smithfield" };
let finalJobs = [];

const s = new scraper.Scraper(url);

s.soup
.then((soup) => {
const jobs = soup.find("div", { class: "jobs" }).findAll("div");

jobs.forEach((job) => {
const id = uuid.v4();
const job_title = job.find("span", { class: "first" }).text.trim();
const job_link = job.find("span", { class: "second" }).find("a")
.attrs.href;

finalJobs.push({
id: id,
job_title: job_title,
job_link: job_link,
company: company.company,
country: "Romania",
city: "Romania",
});
});
})
.then(() => {
console.log(JSON.stringify(finalJobs, null, 2));

scraper.postApiPeViitor(finalJobs, company);

let logo = "https://www.smithfield.ro/assets/app/images/logo.png";

let postLogo = new scraper.ApiScraper(
"https://api.peviitor.ro/v1/logo/add/"
);
postLogo.headers.headers["Content-Type"] = "application/json";
postLogo.post(JSON.stringify([{ id: company.company, logo: logo }]));
});
const { Scraper, postApiPeViitor } = require("peviitor_jsscraper");

const generateJob = (job_title, job_link) => ({
job_title,
job_link,
country: "Romania",
city: "Timisoara",
county: "Timis",
remote: [],
});

const getJobs = async () => {
const url = "https://www.smithfield.ro/ro/cariere/posturi-disponibile";
const jobs = [];
const scraper = new Scraper(url);

const res = await scraper.get_soup("HTML");

const jobsElements = res.find("div", { class: "jobs" }).findAll("div");

jobsElements.forEach((job) => {
const job_title = job.find("span", { class: "first" }).text.trim();
const job_link = job.find("span", { class: "second" }).find("a").attrs.href;

jobs.push(generateJob(job_title, job_link));
});

return jobs;
};

const getParams = () => {
const company = "Smithfield";
const logo =
"https://www.smithfield.ro/assets/app/images/logo.png";
const apikey = process.env.APIKEY;
const params = {
company,
logo,
apikey,
};
return params;
};

const run = async () => {
const jobs = await getJobs();
const params = getParams();
postApiPeViitor(jobs, params);
};

if (require.main === module) {
run();
}

module.exports = { run, getJobs, getParams }; // this is needed for our unit test job

0 comments on commit 097d876

Please sign in to comment.