【发布时间】:2021-06-19 18:17:33
【问题描述】:
您好,我正在实现一个 scraper,它会抓取在电报公共频道中收到的最新消息。这就是html的
我可以获取tgme_channel_history 部分类下的所有 div。它下面有五个 div,这意味着五个不同的消息。我只想得到最后一个 div。我怎样才能做到这一点。
您可以在此处查看实时 HTML https://telegram.me/s/newlink01/
const $ = require('cheerio');
const url = 'https://telegram.me/s/newlink01/';
rp(url)
.then(function (html) {
//success!
const wikiUrls = [];
$('.tgme_channel_history', html).each(function () {
wikiUrls.push($(this).text()
});
console.log(wikiUrls[0]);
})
.catch(function (err) {
//handle error
});
【问题讨论】:
标签: javascript jquery node.js cheerio