From e4099fca9eafb7fbcfa58f3bcd4992fce07f2fe1 Mon Sep 17 00:00:00 2001 From: Vishwa Gaurav <81325730+VishwaGauravIn@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:40:23 +0530 Subject: [PATCH] =?UTF-8?q?linkedin=20checks=20bypass=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index fae7797..3a4388f 100644 --- a/index.js +++ b/index.js @@ -7,12 +7,8 @@ module.exports.query = (queryObject) => { return query.getJobs(); }; -//transfers object values passed to our .query to an obj we can access function Query(queryObj) { - //query vars this.host = queryObj.host || "www.linkedin.com"; - - //api handles strings with spaces by replacing the values with %20 this.keyword = queryObj.keyword?.trim().replace(" ", "+") || ""; this.location = queryObj.location?.trim().replace(" ", "+") || ""; this.dateSincePosted = queryObj.dateSincePosted || ""; @@ -21,17 +17,9 @@ function Query(queryObj) { this.salary = queryObj.salary || ""; this.experienceLevel = queryObj.experienceLevel || ""; this.sortBy = queryObj.sortBy || ""; - //internal variable this.limit = Number(queryObj.limit) || 0; } -/* - * - * - * Following get Functions act as object literals so the query can be constructed with the correct parameters - * - * - */ Query.prototype.getDateSincePosted = function () { const dateRange = { "past month": "r2592000", @@ -85,16 +73,6 @@ Query.prototype.getSalary = function () { return salaryRange[this.salary.toLowerCase()] ?? ""; }; -/* - * EXAMPLE OF A SAMPLE QUERY - * https://www.linkedin.com/jobs/search/?f_E=2%2C3&f_JT=F%2CP&f_SB2=1&f_TPR=r2592000&f_WT=2%2C1&geoId=90000049&keywords=programmer&location=Los%20Angeles%20Metropolitan%20Area - * Date Posted (Single Pick) f_TPR - * Job Type (Multiple Picks) f_JT - * Experience Level(Multiple Picks) f_E - * On-Site/Remote (Multiple Picks) f_WT - * Salary (Single Pick) f_SB2 - * - */ Query.prototype.url = function (start) { let query = `https://${this.host}/jobs-guest/jobs/api/seeMoreJobPostings/search?`; if (this.keyword !== "") query += `keywords=${this.keyword}`; @@ -124,37 +102,40 @@ Query.prototype.getJobs = async function () { allJobs = []; while (resultCount > 0) { - //fetch our data using our url generator with - //the page to start on - const { data } = await axios.get(this.url(start)); + const { data } = await axios.get(this.url(start), { + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36", + Accept: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.9", + "Accept-Encoding": "gzip, deflate, br", + Connection: "keep-alive", + "Upgrade-Insecure-Requests": "1", + }, + }); - //select data so we can check the number of jobs returned const $ = cheerio.load(data); const jobs = $("li"); - //if result count ends up being 0 we will stop getting more jobs resultCount = jobs.length; console.log("I got ", jobs.length, " jobs"); - //to get the job data as objects with the desired details parsedJobs = parseJobList(data); allJobs.push(...parsedJobs); - //increment by 25 bc thats how many jobs the AJAX request fetches at a time start += 25; - //in order to limit how many jobs are returned - //this if statment will return our function value after looping and removing excess jobs if (jobLimit != 0 && allJobs.length > jobLimit) { while (allJobs.length != jobLimit) allJobs.pop(); return allJobs; } } - //console.log(allJobs) return allJobs; } catch (error) { console.error(error); } }; + function parseJobList(jobData) { const $ = cheerio.load(jobData); const jobs = $("li");