【问题标题】:CheerioJS and some issue with scrapingCheerioJS 和一些抓取问题
【发布时间】:2021-02-04 03:47:13
【问题描述】:

我用cheerio 抓取了html,我想从中获取 class="title" ......我该怎么做?我尝试以多种方式做到这一点,但它不起作用..在 console.log 之后它返回 null。

<div class="beatmap" id="914524" style="width:420px;">
    <div class="bmlistt" style="background: 
        url(&quot;//b.ppy.sh/thumb/914524.jpg&quot;)">
        <i class="icon-play"></i>
    </div>

    <div class="bmlist-options" style="display: none; overflow: hidden; width: 24px;">
        <a href="#"><i class="icon-heart"></i></a>
        <a href="/forum/t/858871"><i class="icon-comments"></i></a>
        <a class="require-login beatmap_download_link" href="/d/914524"><i class="icon-download-alt"></i></a>
    </div>

    <div class="maintext" stop="1">
        <span class="artist">ZUN</span>
        <a href="/s/914524" class="title">Haru no Minato ni</a>
    </div>
</div>

这里是抓取的代码。告诉我如何将 class="title" 抓取到控制台并转换为文本。

【问题讨论】:

  • 请问你的失败代码在哪里?

标签: javascript web-scraping cheerio


【解决方案1】:
const $ = cheerio.load(content);
const text = $('.title').text();
console.log(text);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2021-07-16
    • 1970-01-01
    相关资源
    最近更新 更多