【问题标题】:how to scrape trending song names from music websites like hungama or saavn如何从诸如 hangama 或 saavn 之类的音乐网站上抓取热门歌曲名称
【发布时间】:2017-09-06 12:14:33
【问题描述】:

我的需要是从类似的 hangama 或 saavn 中获取热门歌曲/专辑名称。我使用来自 npm 的网络抓取包并尝试从网站检索数据。参考了很多包,比如cheerio、jsdom、request等。终于找到了一个简单的包,叫做“osmosis”。这是我使用渗透的代码。

const osmosis = require('osmosis');

osmosis
    .get('http://www.hungama.com/all/top-songs-51/21825/')
    .find('.listing div.block-cont div.song div.song-name')
    .follow('h4')
    .log(console.log)

这将返回如下输出:

(get) loaded [get] http://www.hungama.com/all/top-songs-51/21825/  
(find) found 12 results for ".listing div.block-cont div.song div.song-name" 
(follow) url: 
                                            
                                            Mersal Arasan                                        
(follow) url: 
                                            
                                            Yaanji                                       
(follow) url: 
                 
(follow) loaded [get] http://www.hungama.com/all/top-songs-51/21825/Mersal%20Arasan  
(follow) loaded [get] http://www.hungama.com/all/top-songs-51/21825/Yaanji  

但我只需要输出歌曲名称。在使用其他包(如cheerio)时,如何在查找时提及我的特定数据类(例如如何提及“div.listing div.song div.song-name h4”)。有没有其他简单的方法来执行此操作。请帮助我找到我的解决方案。

【问题讨论】:

    标签: javascript node.js npm web-scraping


    【解决方案1】:

    试试这个:

    const osmosis = require('osmosis');
    
    osmosis
        .get('http://www.hungama.com/all/top-songs-51/21825/')
        .find('div.song-name')
        // ^^^^^ assuming this is the css selector for the song name
        .set('songName')
        .data(function(names){
                console.log(names); // display the list of songName sa object.
             })
        .log(console.log)
        .error(console.log)
        .debug(console.log)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      相关资源
      最近更新 更多