我有一个看起来像这样的页面。
<li title="Sulphurous" class='item q-440-5 q-440-border-5' data-tip="top" >
<a href="/effect/Sulphurous"><div class='item-icon' style='background-image:url(),url(/images/440/particles/64_94x94.png)'></div><div class='tag bottom-right'>avg 207.61</div><div class='tag top-left'>sulphurous</div></a>
<span style='display:none'>Unusual Sulphurous</span></li>
<li title="Purple Confetti" class='item q-440-5 q-440-border-5' data-tip="top" >
<a href="/effect/Purple%20Confetti"><div class='item-icon' style='background-image:url(),url(/images/440/particles/7_94x94.png)'></div><div class='tag bottom-right'>avg 57.39</div><div class='tag top-left'>p.fetti</div></a>
<span style='display:none'>Unusual Purple Confetti</span></li>
我想提取 title
和 tag bottom-right
. 结果应该是这样的。
name: Unusual Sulphurous
price: avg 207.61
name: Unusual Purple Confetti
price: avg 57.39
我如何提取 avg 207.61
和 avg 57.39
使用cheerio?
我只能解析标题。这是我的脚本。
$('li').each(function(){
var name = ($(this).attr('title'));
var price = ($(this).attr('tag bottom-right'));
nameList.push({
name: name,
price: price,
});
});
但价格是... undefined
. 我试过 tag_bottom-right
, tag-bottom-right
, tag.bottom-right
和 .tag.bottom-right
但还是不行。
也试过这样做。
$("tag.bottom-right").each(function() {
let id = ($(this).data("tag.bottom-right"));
});
但还是 undefined
. 我到底做错了什么?
你没有使用正确的CSS。
let prices = $(".tag.bottom-right").map((i, el) => $(el).text())