【发布时间】:2019-07-03 18:49:12
【问题描述】:
我有一些代码,我得到了 div 类的第一个孩子的响应,我想从我的 first 变量中获取 993307。我该怎么做?
<a href="https://osu.ppy.sh/beatmapsets/993307/discussion#/1050967" title="MIIRO (TV Size) - AKINO from bless4 (mapped by Sotarks)">
const cheerio = require('cheerio');
const rp = require('request-promise');
var array = [];
rp(`https://osu.ppy.sh/beatmapsets/events?user=&types%5B%5D=disqualify&min_date=&max_date=`)
.then((html) => {
let $ = cheerio.load(html);
$('div#events.beatmapset-events').each(function(i, element) {
var first = $(this).children().eq(1);
console.log(first.html())
})
})
.catch(console.error.bind(console));
这是来自first变量的回复
<div class="beatmapset-event">
<a href="https://osu.ppy.sh/beatmapsets/993307/discussion#/1050967" title="
MIIRO (TV Size) - AKINO from bless4
(mapped by Sotarks)
">
<img class="beatmapset-activities__beatmapset-cover" src="https://assets.ppy.sh/beatmaps/993307/covers/list.jpg?1562167122" srcset="https://assets.ppy.sh/beatmaps/993307/covers/list.jpg?156216712
2 1x, https://assets.ppy.sh/beatmaps/993307/covers/list@2x.jpg?1562167122 2x">
</a>
<div class="beatmapset-event__icon beatmapset-event__icon--disqualify beatmapset-activities__event-icon-spacer"></div>
<div>
<div class="beatmapset-event__content">
Disqualified by <a class="user-name js-usercard" data-user-id="3388410" href="https://osu.ppy.sh/users/3388410" style="color: #6B3FA0">eiri-</a>. Reason: <a href="https://osu.ppy.sh/beatmapsets/9
93307/discussion#/1050967">#1050967</a> ([no preview]).
</div>
<div><time class="timeago" datetime="2019-07-03T15:17:20+00:00">July 3, 2019 at 3:17:20 PM UTC</time></div>
</div>
</div>
【问题讨论】:
-
是字符串吗?还是一个 html 节点?
标签: javascript html cheerio request-promise