微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cheerio Web Scape:标签之间没有换行符

如何解决Cheerio Web Scape:标签之间没有换行符

当我使用 $('.episode-title') 时,我得到的输出

Otona no Bouguya-san S2 — 02Otona no Bouguya-san S2 — 01

我想要的输出Otona no Bouguya-san S2 — 02 \n Otona no Bouguya-san S2 — 01

我该怎么做?

编辑 1 我的代码

const Nightmare = require('nightmare');
const cheerio = require('cheerio');
const url = `https://subsplease.org/shows/otona-no-bouguya-san-s2/`
const nightmare = Nightmare({ show: true })

// Request making using nightmare
nightmare
  .goto(url)
  .wait('body')
  .wait('label.episode-title')
  .evaluate(() => document.querySelector('body').innerHTML)
  .end()
  .then(response => {
    console.log(getData(response));
  }).catch(err => {
    console.log(err);
  });


let getData = html => {
    const $ = cheerio.load(html);

    let title = $('.episode-title').text()
    console.log(title)
}

编辑 2 JSON

{
    "episodes": [ 
       {
        "title": "Otona no Bouguya-san S2 — 01","torrents": [
            {
                "resolution": "1080p","magnet": "url","torrent": "url"
            },{
                "resolution": "720p",{
                "resolution": "sd","torrent": "url"
            }
            
        ]
       },{
        "title": "Otona no Bouguya-san S2 — 02","torrent": "url"
            }
            
        ]
       } 
    ]
}

解决方法

第一次使用:

$('.episode-title').first().text()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。