获取 div 数据,其 class 字段中有空格

Getting div data which has empty spaces in its class field

我有一个需要解析的页面:

<div class="shadowBox someOtherBox">
    .
    .
    .
</div>

.
.
.
<div class="shadowBox other">
    <h2>OTHERS</h2>
    <ul>
        <li>
            <a href="/link/to/something/1" target="_self">TITLE #1</a>
        </li>
        <li>
            <a href="/link/to/something/2" target="_self">TITLE #2</a>
        </li>
        <li>
            <a href="/link/to/something/3" target="_self">TITLE #3</a>
        </li>
    </ul>
</div>

我想获取 <div class="shadowBox other"> 中的每个 link 及其标题。我尝试以多种不同的方式来做到这一点,但最后我无法做到。这是我的一次尝试的代码;

function parse(crn)
    {
        request("LINK_OF_PAGE", function(error, response, html)
        {
            if(!error)
            {
                var $ = cheerio.load(html);
                var title, news_url, url_hash;
                var json = { title : "", news_url : ""};

                var links = [];

                var data = $('div').filter('.shadowBox').last();

                //var data = $('.shadowBox.other').children('ul').children('li').children('a');
                console.log(data);

                news_url = data.prev().text();
                url_hash = md5(news_url);
            }
        });
    }

为什么我的逻辑不起作用?我将如何实现我想要的?

看起来您正在尝试使用锚元素的 href 和文本值填充链接数组然后

var links = $('.shadowBox.other li a').map(function(){
    var $this = $(this);
    return { title : $this.attr('href'), news_url : $this.text()}
}).get();