Cheerio 选择具有多个类并用空格分隔的元素

Bab*_*sta 3 node.js web-scraping cheerio

我有这个 html,只想选择类为“图像容器景观”的 div。

<div class="image-container landscape">
        ...
</div>
...
<div class="image-container portrait">
        ...
</div>
Run Code Online (Sandbox Code Playgroud)

使用$(element).find('.image-container')选择第一个 div 中的一个。但我只想要带有“风景”的那一张。我尝试使用$(element).find('.image-container landscape')但它不起作用,也许是因为它假设landscape是一个标签。我该怎么做呢?

pgu*_*rio 9

是的,它会假设风景是一个标签。您想要:

[class="image-container landscape"]

或者

.image-container.landscape

这只是 CSS3 的记录,您可能可以在不到一个小时的时间内阅读完整的规范。