alsotang / node-lessons

:closed_book:《Node.js 包教不包会》 by alsotang
16.54k stars 4.7k forks source link

lesson3 项目:cheerio 的选择器问题 #163

Closed befriend1314 closed 5 years ago

befriend1314 commented 5 years ago

我爬一个列表页,结构如下:

<ul id="waterfall">
  <li class="item mylist"></li>
  <li class="item mylist"></li>
  <li class="item mylist"></li>
  <li class="item mylist"></li>
</ul>

js 部分:

let $ = cheerio.load(sres.text);
$('#waterfall .mylist').each(function (idx, element) {
...
});

当li 有两个类名的时候, 貌似用第二个类名是取不到的,要这么写才行:

$('#waterfall .item').each(function (idx, element) {
...
});
befriend1314 commented 5 years ago

是我搞错了