JavaScript-如何从元素中获取正确的内容
我正在尝试运行一个JavaScript,该JavaScript将从网页上提取工资,进行计算,然后编辑网页以显示一个新号码(自动右键单击 - > Inspect)。
我一直在遵循有关如何刮擦网页并将所需元素放入.txt文件中的指南。我已经修改了查找工作薪水的代码。但是,当我运行节点时。刮擦。
有什么方法我只能完成薪水吗?下面的代码。
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');
});
});
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');
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论