Javascript - how to pull the correct content from an element

Viewed 24

I am trying to run a javascript that will pull salaries off a webpage, do a calculation, then edit the webpage to show a new number (automating right click -> inspect).

I have been following a guide on how to scrape a webpage and put the desired elements into a .txt file. I have amended the code to look up salaries of jobs. However when I run node. scrapesalaries.js it pulls through the location and the salary.

Is there a way I can only pull through the salary? Code below.

var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');

request("https://www.reed.co.uk/jobs/manager-jobs", function(error, response, body) {
  if(error) {
    console.log("Error: " + error);
  }
  console.log("Status code: " + response.statusCode);

  var $ = cheerio.load(body);

  $('div.row:has(ul.job-metadata)').each(function( index ) {
    var title = $(this).find('ul.job-metadata > li').text().trim();
    var link = $(this).find('ul.job-metadata > li').attr('href');
    fs.appendFileSync('salaries.txt', title + '\n' + link + '\n');
  });

});
0 Answers
Related