linkedin-jobs-api
Advanced tools
Comparing version 1.0.3 to 1.0.4
47
index.js
const cheerio = require("cheerio"); | ||
const axios = require("axios"); | ||
const randomUseragent = require("random-useragent"); | ||
@@ -10,8 +11,4 @@ module.exports.query = (queryObject) => { | ||
//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(" ", "+") || ""; | ||
@@ -25,13 +22,5 @@ this.location = queryObj.location?.trim().replace(" ", "+") || ""; | ||
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 () { | ||
@@ -90,12 +79,2 @@ const dateRange = { | ||
/* | ||
* 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) { | ||
@@ -130,22 +109,26 @@ let query = `https://${this.host}/jobs-guest/jobs/api/seeMoreJobPostings/search?`; | ||
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 userAgent = randomUseragent.getRandom(); | ||
//select data so we can check the number of jobs returned | ||
const { data } = await axios.get(this.url(start), { | ||
headers: { | ||
"User-Agent": userAgent, | ||
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", | ||
}, | ||
}); | ||
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) { | ||
@@ -156,3 +139,2 @@ while (allJobs.length != jobLimit) allJobs.pop(); | ||
} | ||
//console.log(allJobs) | ||
return allJobs; | ||
@@ -163,2 +145,3 @@ } catch (error) { | ||
}; | ||
function parseJobList(jobData) { | ||
@@ -165,0 +148,0 @@ const $ = cheerio.load(jobData); |
{ | ||
"name": "linkedin-jobs-api", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "advanced node.js package for getting job listings from LinkedIn", | ||
@@ -29,4 +29,5 @@ "main": "index.js", | ||
"axios": "^0.27.2", | ||
"cheerio": "^1.0.0-rc.12" | ||
"cheerio": "^1.0.0-rc.12", | ||
"random-useragent": "^0.5.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23729
3
180
+ Addedrandom-useragent@^0.5.0
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedrandom-seed@0.3.0(transitive)
+ Addedrandom-useragent@0.5.0(transitive)