首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >万维网开景:标签之间没有断线

万维网开景:标签之间没有断线
EN

Stack Overflow用户
提问于 2021-01-11 20:53:49
回答 2查看 92关注 0票数 1

当我使用$('.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 My代码

代码语言:javascript
复制
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

代码语言:javascript
复制
{
    "episodes": [ 
       {
        "title": "Otona no Bouguya-san S2 — 01",
        "torrents": [
            {
                "resolution": "1080p",
                "magnet": "url",
                "torrent": "url"
            },
            {
                "resolution": "720p",
                "magnet": "url",
                "torrent": "url"
            },            
            {
                "resolution": "sd",
                "magnet": "url",
                "torrent": "url"
            }
            
        ]
       }, 
       {
        "title": "Otona no Bouguya-san S2 — 02",
        "torrents": [
            {
                "resolution": "1080p",
                "magnet": "url",
                "torrent": "url"
            },
            {
                "resolution": "720p",
                "magnet": "url",
                "torrent": "url"
            },            
            {
                "resolution": "sd",
                "magnet": "url",
                "torrent": "url"
            }
            
        ]
       } 
    ]
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-11 21:38:51

由于.episode-title类有两个元素,所以应该使用mapforEach。这里有一个:

代码语言:javascript
复制
let titles = $('.episode-title').map((i, el) => $(el).text()).get();
console.log(titles);

// => ["Otona no Bouguya-san S2 — 02", "Otona no Bouguya-san S2 — 01"]
票数 0
EN

Stack Overflow用户

发布于 2021-01-12 07:13:44

第一次使用:

代码语言:javascript
复制
$('.episode-title').first().text()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65674381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档