我想刮这张桌子的风柱https://www.bmreports.com/bmrs/?q=generation%2Ffueltype&fbclid=IwAR2p2a84CaJhgzF-YOU4MzOS-cMuZUpeDmLHFkWZU7-NauRHrA1owwdsMog 我可以刮整个桌子,但我不知道怎么做对其进行排序。理想情况下,我只会刮掉一列。const request = require('request');const cheerio = require('cheerio');request('https://www.bmreports.com/bmrs/?q=generation%2Ffueltype&fbclid=IwAR2p2a84CaJhgzF-YOU4MzOS-cMuZUpeDmLHFkWZU7-NauRHrA1owwdsMog', (error, response, html) =>{ if (!error && response.statusCode == 200) { const $ = cheerio.load(html); const table = $('.gen-fuel'); var newArray = []; var windArray = []; // console.log(table.html()); $('td').each((i, el) => { const item = $(el).html(); newArray.push(item); console.log(item) }); const every7thValue = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1); console.log(every7thValue(newArray, 7)); //console.log(newArray); }});
1 回答
喵喵时光机
TA贡献1846条经验 获得超7个赞
像这样的东西怎么样
const request = require('request');
const cheerio = require('cheerio');
request(
'https://www.bmreports.com/bmrs/?q=generation%2Ffueltype&fbclid=IwAR2p2a84CaJhgzF-YOU4MzOS-cMuZUpeDmLHFkWZU7-NauRHrA1owwdsMog',
(error, response, html) => {
if (!error && response.statusCode == 200) {
const $ = cheerio.load(html);
const winds = $('.gen-fuel tbody td:nth-child(8)')
.map(function () {
return $(this).text();
})
.get();
console.log(winds);
}
}
);
Cheerio 支持 CSS 选择器,凭借其强大的功能,您可以获得包含来自风列的所有值的数组
添加回答
举报
0/150
提交
取消