[Ruby]试用Hpricot抓百度新歌榜

    技术2022-05-11  71

    Hpricot支持像 jQurey一样的Css Selector 下面的代码抓取百度新歌Top100的歌名及歌手名单: require   " open-uri " require   " hpricot " doc  =   open ( " http://list.mp3.baidu.com/list/newhits.html?id=1#top1 " ) {  | f |  Hpricot(f) }doc . search( " .border " ) . each   do   | table |   table . search( " a " ) . each   do   | link |      print   link . inner_html  end  putsend  速度快得不得了,这得益于 Ragel生成器^_^ 现在Hpricot除了Win32/Src版外,还提供了JRuby版的。 

    最新回复(0)