这里使用ruby里面非常实用的库 mechanize和hpricot
sudo gem install hpricot
sudo gem install mechanize
head.html
<
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< meta name ="author" content =" [email]service@yobo.com[/email] " />
< meta name ="Copyright" content ="www.yobo.com 版权所有,违者必究" />
< title >飙升榜单 < YOBO - YOBO 友播 音乐DNA </ title>
< meta name ="keywords" content ="飙升榜单,YOBO,音乐DNA,音乐心理测试,音乐推荐,免费音乐,在线试听,YOBO,友播" />
< meta name ="description" content ="在YOBO查看单曲飙升榜" />
< link rel ="shortcut icon" href ="/favicon.ico" />
< link href ="http://assets.yobo.com/stylesheets/yobo_nav_v4.11590.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< link href ="http://assets.yobo.com/stylesheets/yobo_base.10705.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< link href ="http://assets.yobo.com/stylesheets/yobo_feed.11912.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< script src ="http://assets.yobo.com/javascripts/base.9902.js" type ="text/javascript" > </script>
< script src ="http://assets.yobo.com/javascripts/yobo_nav.10930.js" type ="text/javascript" > </script>
< script language ="javascript" type ="text/javascript" src ="http://assets.yobo.com/javascripts/fckeditor/fckeditor.js" > </script>
< script language ="javascript" type ="text/javascript" src ="http://assets.yobo.com/javascripts/yobo_const_10839.js" charset ="utf-8" > </script>
< link href ="http://assets.yobo.com/stylesheets/yobo_aggr.8548.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< script src ="http://assets.yobo.com/javascripts/yobo_base.11954.js" type ="text/javascript" > </script>
< script src ="http://assets.yobo.com/javascripts/yobo_aggr.7969.js" type ="text/javascript" > </script>
</head>
< body >
< script type ="text/javascript" >
var s_rise_playlist = [];
</script>
< form id ="aggrmusicrise_risetable" class ="aggr_block" onsubmit ="return false;" >
< table class ="aggrmusic_risetable" cellpadding ="0" cellspacing ="0" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< meta name ="author" content =" [email]service@yobo.com[/email] " />
< meta name ="Copyright" content ="www.yobo.com 版权所有,违者必究" />
< title >飙升榜单 < YOBO - YOBO 友播 音乐DNA </ title>
< meta name ="keywords" content ="飙升榜单,YOBO,音乐DNA,音乐心理测试,音乐推荐,免费音乐,在线试听,YOBO,友播" />
< meta name ="description" content ="在YOBO查看单曲飙升榜" />
< link rel ="shortcut icon" href ="/favicon.ico" />
< link href ="http://assets.yobo.com/stylesheets/yobo_nav_v4.11590.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< link href ="http://assets.yobo.com/stylesheets/yobo_base.10705.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< link href ="http://assets.yobo.com/stylesheets/yobo_feed.11912.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< script src ="http://assets.yobo.com/javascripts/base.9902.js" type ="text/javascript" > </script>
< script src ="http://assets.yobo.com/javascripts/yobo_nav.10930.js" type ="text/javascript" > </script>
< script language ="javascript" type ="text/javascript" src ="http://assets.yobo.com/javascripts/fckeditor/fckeditor.js" > </script>
< script language ="javascript" type ="text/javascript" src ="http://assets.yobo.com/javascripts/yobo_const_10839.js" charset ="utf-8" > </script>
< link href ="http://assets.yobo.com/stylesheets/yobo_aggr.8548.css" media ="screen" rel ="Stylesheet" type ="text/css" />
< script src ="http://assets.yobo.com/javascripts/yobo_base.11954.js" type ="text/javascript" > </script>
< script src ="http://assets.yobo.com/javascripts/yobo_aggr.7969.js" type ="text/javascript" > </script>
</head>
< body >
< script type ="text/javascript" >
var s_rise_playlist = [];
</script>
< form id ="aggrmusicrise_risetable" class ="aggr_block" onsubmit ="return false;" >
< table class ="aggrmusic_risetable" cellpadding ="0" cellspacing ="0" >
end.html
</table>
</form>
< div id ="yobosongplayerblock" style ="height:1px;" >
< object classid ="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase ="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0" width ="1" height ="1" id ="pagesongplayer" align ="middle" >
< param name ="allowScriptAccess" value ="always" />
< param name ="movie" value ="http://assets.yobo.com/flash/sh/shell.swf" />
< param name ="quality" value ="high" />
< param name ="bgcolor" value ="#ffffff" />
< embed src ="http://assets.yobo.com/flash/sh/shell.swf" quality ="high" bgcolor ="#ffffff" width ="1" height ="1" name ="pagesongplayer" align ="middle" allowScriptAccess ="always" type ="application/x-shockwave-flash" pluginspage ="http://www.macromedia.com/go/getflashplayer" > </embed>
</object>
< object classid ="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase ="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0" width ="1" height ="1" id ="popconnector" align ="middle" >
< param name ="allowScriptAccess" value ="always" />
< param name ="movie" value ="http://assets.yobo.com/flash/pop/local_8657.swf" />
< param name ="quality" value ="high" />
< param name ="bgcolor" value ="#ffffff" />
< embed src ="http://assets.yobo.com/flash/pop/local_8657.swf" quality ="high" bgcolor ="#ffffff" width ="1" height ="1" name ="popconnector" align ="middle" allowScriptAccess ="always" type ="application/x-shockwave-flash" pluginspage ="http://www.macromedia.com/go/getflashplayer" > </embed>
</object>
</div>
< div id ="yoboaggr_floathintdialog" style ="position:absolute; width:290px; left:0px; top:0px; display:none; z-index:4000;" >
< div style ="height:7px; font-size:1px; background:url(/p_w_picpaths/icons/aggr_floathintbg.gif) no-repeat left bottom;" > </div>
< div style ="border-left:1px solid #c2d7ea; border-right:1px solid #c2d7ea; border-bottom:1px solid #c2d7ea; padding:3px 8px; background-color:#f4faff; line-height:20px; color:#006ad0;" >
< div id ="yoboaggr_floathintdialogheader" style ="font-weight:bold; display:none;" > </div>
< div id ="yoboaggr_floathintdialogcontent" > </div>
</div>
</div>
< div style ="position:absolute; left:-1000px; top:-1000px" >
< img src ="/p_w_picpaths/icons/yoboheaderlinkbg.gif" />
< img src ="/p_w_picpaths/icons/leftbar_linkbg.gif" />
< img src ="/p_w_picpaths/icons/leftbar_coloricons.gif" />
< img src ="/p_w_picpaths/icons/leftbar_hovericons.gif" />
< img src ="/p_w_picpaths/icons/indexme_feedbg2.gif" />
< img src ="/p_w_picpaths/icons/userbox_iconcolor.gif" />
</div>
< script language ="javascript" type ="text/javascript" >
//initPageInterface();
window.setTimeout('initPageInterface()', 1000);
//Event.observe(window, "load", yobo_oninitpageplayer.bindAsEventListener(this));
</script>
</div>
< script language ="javascript" type ="text/javascript" >
var v = "0.0424833368770254";
</script>
< script type ="text/javascript" >
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write("\ < script src ='" + gaJsHost + "google-analytics.com/ga.js' type ='text/javascript' >\ < \/script >" );
</script>
< script type ="text/javascript" >
var pageTracker = _gat._getTracker("UA-848223-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>
</form>
< div id ="yobosongplayerblock" style ="height:1px;" >
< object classid ="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase ="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0" width ="1" height ="1" id ="pagesongplayer" align ="middle" >
< param name ="allowScriptAccess" value ="always" />
< param name ="movie" value ="http://assets.yobo.com/flash/sh/shell.swf" />
< param name ="quality" value ="high" />
< param name ="bgcolor" value ="#ffffff" />
< embed src ="http://assets.yobo.com/flash/sh/shell.swf" quality ="high" bgcolor ="#ffffff" width ="1" height ="1" name ="pagesongplayer" align ="middle" allowScriptAccess ="always" type ="application/x-shockwave-flash" pluginspage ="http://www.macromedia.com/go/getflashplayer" > </embed>
</object>
< object classid ="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase ="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0" width ="1" height ="1" id ="popconnector" align ="middle" >
< param name ="allowScriptAccess" value ="always" />
< param name ="movie" value ="http://assets.yobo.com/flash/pop/local_8657.swf" />
< param name ="quality" value ="high" />
< param name ="bgcolor" value ="#ffffff" />
< embed src ="http://assets.yobo.com/flash/pop/local_8657.swf" quality ="high" bgcolor ="#ffffff" width ="1" height ="1" name ="popconnector" align ="middle" allowScriptAccess ="always" type ="application/x-shockwave-flash" pluginspage ="http://www.macromedia.com/go/getflashplayer" > </embed>
</object>
</div>
< div id ="yoboaggr_floathintdialog" style ="position:absolute; width:290px; left:0px; top:0px; display:none; z-index:4000;" >
< div style ="height:7px; font-size:1px; background:url(/p_w_picpaths/icons/aggr_floathintbg.gif) no-repeat left bottom;" > </div>
< div style ="border-left:1px solid #c2d7ea; border-right:1px solid #c2d7ea; border-bottom:1px solid #c2d7ea; padding:3px 8px; background-color:#f4faff; line-height:20px; color:#006ad0;" >
< div id ="yoboaggr_floathintdialogheader" style ="font-weight:bold; display:none;" > </div>
< div id ="yoboaggr_floathintdialogcontent" > </div>
</div>
</div>
< div style ="position:absolute; left:-1000px; top:-1000px" >
< img src ="/p_w_picpaths/icons/yoboheaderlinkbg.gif" />
< img src ="/p_w_picpaths/icons/leftbar_linkbg.gif" />
< img src ="/p_w_picpaths/icons/leftbar_coloricons.gif" />
< img src ="/p_w_picpaths/icons/leftbar_hovericons.gif" />
< img src ="/p_w_picpaths/icons/indexme_feedbg2.gif" />
< img src ="/p_w_picpaths/icons/userbox_iconcolor.gif" />
</div>
< script language ="javascript" type ="text/javascript" >
//initPageInterface();
window.setTimeout('initPageInterface()', 1000);
//Event.observe(window, "load", yobo_oninitpageplayer.bindAsEventListener(this));
</script>
</div>
< script language ="javascript" type ="text/javascript" >
var v = "0.0424833368770254";
</script>
< script type ="text/javascript" >
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write("\ < script src ='" + gaJsHost + "google-analytics.com/ga.js' type ='text/javascript' >\ < \/script >" );
</script>
< script type ="text/javascript" >
var pageTracker = _gat._getTracker("UA-848223-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>
然后呢, 打开你最习惯的代码编辑器, 使用如下代码
yobo_music.rb
require "rubygems"
require "mechanize"
agent = WWW::Mechanize.new
page = agent.get "http://www.yobo.com/s/rise?fr=2"
musics = page.search "//td.risesong"
tm = File.new("tm.html", "w+")
head = File.new("head.html", "r")
tm.syswrite head.read
head.close
musics.each do |music|
tm.syswrite "<tr>"
tm.syswrite music.to_html
tm.syswrite "</tr>"
end
end_file = File.new("end.html", "r")
tm.syswrite end_file.read
end_file.close
tm.close
require "mechanize"
agent = WWW::Mechanize.new
page = agent.get "http://www.yobo.com/s/rise?fr=2"
musics = page.search "//td.risesong"
tm = File.new("tm.html", "w+")
head = File.new("head.html", "r")
tm.syswrite head.read
head.close
musics.each do |music|
tm.syswrite "<tr>"
tm.syswrite music.to_html
tm.syswrite "</tr>"
end
end_file = File.new("end.html", "r")
tm.syswrite end_file.read
end_file.close
tm.close
最后, 我未检测过是否必须登录才可以听歌, 如果确实要登录, 你可以尝试这样
yobo_login.rb
require "rubygems"
require "mechanize"
agent = WWW::Mechanize.new
page = agent.get "http://www.yobo.com/s/rise?fr=2"
forms = page.forms
login_form = form[3]
#用户邮箱
login_form.fields[0] = "[email]xxx@xxx.com[/email]"
#密码
login_form.fields[1] = "xxxxxxxx"
#登录
page = agent.submit login_form
require "mechanize"
agent = WWW::Mechanize.new
page = agent.get "http://www.yobo.com/s/rise?fr=2"
forms = page.forms
login_form = form[3]
#用户邮箱
login_form.fields[0] = "[email]xxx@xxx.com[/email]"
#密码
login_form.fields[1] = "xxxxxxxx"
#登录
page = agent.submit login_form
转载于:https://blog.51cto.com/andyss/100945