URL
import java.net.MalformedURLException;
import java.net.URL;
public class URLDemo01 {
public static void main(String[] args) throws MalformedURLException {
URL url=new URL("");//引号内需要填入URL地址
System.out.println(url.getProtocol());//协议
System.out.println(url.getHost());//主机IP
System.out.println(url.getPort());//端口
System.out.println(url.getPath());//文件
System.out.println(url.getFile());//全路径
System.out.println(url.getQuery());//参数
}
}
URL下载网络资源
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class UrlDown {
public static void main(String[] args) throws Exception {
//下载地址
URL url=new URL("https://www.kugou.com/song/#hash=5C947EEC7FD807C4E67E249FEDAD4B76&album_id=41808238");//下载地址
//连接到这个资源 HTTP
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
InputStream inputStream=urlConnection.getInputStream();
FileOutputStream fos=new FileOutputStream("1.txt");
byte[] buffer=new byte[1024];
int len;
while((len=inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);//写出这个数据
}
fos.close();
inputStream.close();
urlConnection.disconnect();//断开连接
}
}
下载内容:酷狗音乐
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title> 酷狗音乐-就是歌多 </title>
<meta name="keywords" content=" '酷狗音乐-就是歌多' " />
<meta name="description" content="酷狗音乐旗下最新最全的在线正版音乐网站,本站为您免费提供最全的在线音乐试听下载,以及全球海量电台和MV播放服务、最新音乐播放器下载。酷狗音乐 和音乐在一起。" />
<link href="https://www.kugou.com/favicon.ico" rel="shortcut icon">
<link rel="stylesheet" href="https://www.kugou.com/yy/static/css/play.css?201505211743">
<link rel="dns-prefetch" href="//fs.w.kugou.com">
<link rel="dns-prefetch" href="//login-user.kugou.com">
<script src="https://m3ws.kugou.com/static/js/share/npm/sentry5.6.1.min.js" crossorigin="anonymous"></script>
<script>
Sentry.init({
dsn: "https://fc8678a0071145128f0c8314c07f8407@sentry.kugou.com/33",
// integrations: [new Sentry.Integrations.BrowserTracing()],
sampleRate: 0.1,
})
</script>
<script data-embed="false" type="text/javascript" src="https://www.kugou.com/yy/static/js/play/lib/jquery.js" ></script>
<script >
var dataFromSmarty = [{"hash":null,"author_name":"","song_name":"","audio_name":"","album_id":0,"timelength":0}],//当前页面歌曲信息
playType = "";//当前播放
</script>
<!-- <script>!function(){({QueryString:function(){if(arg1=arguments[0],arg2=arguments[1],arguments.length>1&&""!=arg1&&""!=arg2&&void 0!=arg1&&void 0!=arg2){var b=arguments[0].match(new RegExp("(^|&)"+arg2+"=([^&]*)(&|$)","i"));return null!=b?b[2]:""}if(""!=arg1&&void 0!=arg1){var b=location.hash.match(new RegExp("[#&]"+arg1+"=([^&]*)(&?)","i"));return b?b[1]:b}},iOS9:function(){var version,agent=navigator.userAgent.toLowerCase();if(agent.indexOf("like mac os x")>0){var regStr_saf=/os [d._]*/gi;version=(agent.match(regStr_saf)+"").replace(/[^0-9|_.]/gi,"").replace(/_/gi,".")}var version_str=version+"";return"undefined"!=version_str&&version_str.length>0&&Number(version.substring(0,2))>=9},ipadJumpLink:function(){var _this=this,t1=(new Date).valueOf(),hasApp=!0;_this.iOS9()?location.href="https://mos.kugou.com/universal/":location.href="kugouurlhd://start.weixin",setTimeout(function(){hasApp||(location.href="https://mos.kugou.com/universal/")},4e3),setTimeout(function(){var t2=Date.now();(!t1||t2-t1<3200)&&(hasApp=!1)},3e3)},init:function(){var _this=this,ua=navigator.userAgent.toLowerCase(),android=(/ipad/gi.test(ua),/android|Adr/gi.test(ua)),iphone=/iphone/gi.test(ua);if(/Android|webOS|iPhone|iPod|ipad|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))if(-1!=playType.toString().indexOf("single")&&/ipad/gi.test(navigator.userAgent.toLowerCase()));else{var songmd5Id=location.href.match(/song/(.*).html/)&&location.href.match(/song/(.*).html/)[1];if(null!=songmd5Id&&void 0!==songmd5Id&&""!=songmd5Id){var songmd5Id=songmd5Id.split(",")[0],nextLink="http://m.kugou.com/kgsong/"+songmd5Id+".html?",hash=location.hash;""!=location.search&&(nextLink+=location.search.substr(1)),hash&&""!=hash&&(nextLink+=hash),window.location=nextLink}else if(-1!=location.href.indexOf("zlist")){var listid=_this.QueryString(location.search.substr(1),"listid"),uid=_this.QueryString(location.search.substr(1),"uid"),sign=_this.QueryString(location.search.substr(1),"sign");"undefined"!=listid&&null!=listid&&""!=listid&&"undefined"!=uid&&null!=uid&&""!=uid&&"undefined"!=sign&&null!=sign&&""!=sign&&(window.location="http://m.kugou.com/share/zlist.html"+location.search)}else if(-1!=location.href.indexOf("share")&&location.href.match(/share/(.*).html/)&&"undefined"!=location.href.match(/share/(.*).html/)[1]&&null!=location.href.match(/share/(.*).html/)[1]){var shareId=location.href.match(/share/(.*).html/)[1],nextLink="http://m.kugou.com/share/?chain="+shareId,hash=location.hash;""!=location.search&&(nextLink+="&"+location.search.substr(1)),hash&&""!=hash&&(nextLink+=hash),window.location=nextLink}else android?window.location="http://mo.kugou.com/download/app/index.php?plat=0&fr=kugou":iphone?window.location="http://mo.kugou.com/download/app/index.php?plat=1&fr=kugou":/ipad/i.test(navigator.userAgent)&&_this.ipadJumpLink()}}}).init()}();</script> -->
</head>
<body>
<script data-embed="false" type="text/javascript" src="https://www.kugou.com/yy/static/js/PCToMoblie.js" ></script>
<div class="mainPage">
<div class="header">
<h1 class="logo"><a href="https://www.kugou.com/"><img src="https://staticssl.kugou.com/public/root/images/logo.png" alt=""></a></h1>
<div class="search_wrapper top_search">
<div class="search_input"><input type="text"><div class="searh_btn"><i class="search_icon"></i><span>搜索</span></div></div>
<div class="search_recommend top_search_recommend"></div>
<div class="search_histroy top_search_histroy"></div>
</div>
<div class="topNav fr">
<ul>
<li><a target="_blank" href="https://www.kugou.com/shop/help/serviceCenter">客服中心</a></li>
<li><a target="_blank" href="https://www.kugou.com/hr/kugouHr/dist/index.html">招贤纳士</a></li>
<li><a target="_blank" href="http://vip.kugou.com/">会员中心 </a></li>
</ul>
<div class="login_area">
<div id="login_in" class="clearfix"><a class="login_btn" id="login_btn">登录</a><a target="_blank" href="http://www.kugou.com/reg/web/" class="regin_btn" id="regin_btn">注册</a></div>
<div id="login_out" class="clearfix">
<img class="user_img" src="">
<span class="user_name"></span>
</div>
<div id="user_menu" class="user_menu">
<div class="topArrow1"></div>
<div class="topArrow2"></div>
<ul>
<li><a target="_blank" href="http://www.kugou.com/newuc/user/uc/"><span class="user_icon1"></span>个人帐号</a></li>
<li><a href="https://www.kugou.com/newuc/login/outlogin"><span class="user_icon2"></span>退出登录</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="navWrap">
<div class="nav">
<ul class="homeNav">
<li><a class="normal" href=" https://www.kugou.com/">首页</a></li>
<li><a class="normal" href=" https://www.kugou.com/yy/html/rank.html">榜单</a></li>
<li><a class="normal" id="productCenter" href=" https://download.kugou.com/">下载客户端</a></li>
<li class="more" id="more"><a href="" class="icon icon-nav6" id="showMore">更多</a>
</li>
</ul>
<ul class="secondMenu" id="secondMenu">
<li><a href="https://www.kugou.com/fmweb/html/index.html">电台</a></li>
<li><a href="https://www.kugou.com/mvweb/html/">MV</a></li>
<li><a href="https://www.kugou.com/yy/html/special.html">歌单</a></li>
<li><a href="https://www.kugou.com/yy/html/singer.html">歌手</a></li>
</ul>
<ul class="subNav">
<style>
.navWrap .subNav li{
margin-left: 15px;
}
.navWrap .subNav li.kgPlayer a{
background: url(https://webimg.kgimg.com/eadc2676a352ce14ec5f8050c8c42061.png) no-repeat left center;
}
.navWrap .subNav li.kgPlayer a:hover{
background-image: url(https://webimg.kgimg.com/316067c6630d7375bd5c6503662ae4c4.png);
}
.navWrap .subNav li.openPlat a{
background: url(https://webimg.kgimg.com/7366e06d43da71239d4f2ebd24b4e02e.png) no-repeat left center;
}
.navWrap .subNav li.openPlat a:hover{
background-image: url(https://webimg.kgimg.com/34891849f2a47e7ef62b5fe43b5c46ee.png);
}
</style>
<li><a target="_blank" href="http://fanxing.kugou.com/?action=spreadIndex&id=3" class="icon icon-nav1">直播</a></li>
<li><a target="_blank" href="http://www.kugou.com/shop/product/kugouproduct/index.html" class="icon icon-nav5">商城</a></li>
<!-- <li><a target="_blank" href=" http://live.kugou.com/" class="icon icon-nav2">-酷狗LIVE15</a></li> -->
<li><a target="_blank" href="http://www.kugou.com/imusic/" class="icon icon-nav3">音乐人</a></li>
<!--<li><a target="_blank" href="http://games.kugou.com/?f=7" class="icon icon-nav4">游戏</a></li>-->
<li class="kgPlayer">
<a target="_blank" href="https://sp.kugou.com/" class="icon">代理商</a>
</li>
<li><a target="_blank" href="http://www.kugou.com/fmugc-v2/dist/index.html" class="icon icon-nav8">主播电台</a></li>
<li class="openPlat">
<a target="_blank" href="//open.kugou.com/" class="icon">开放平台</a>
</li>
</ul>
</div>
</div>
<div class="content">
<div class="singerContent clearfix">
<div class="album fl">
<div class="albumImg">
</div>
<div class="btnArea2 clearfix">
<a class="btnDownloadClient" onclick="_hmt.push(['_trackEvent', 'song1software', 'song1download', 'song1kugou']);" ></a>
</div>
<div class="fangxinAd clearfix">
<img class="singerImg" src="">
<div class="singerInfo clearfix">
<div class="singerName">【麦兜是只猪】 正在直播</div>
<div class="singingName">苏打绿-小情歌</div>
<div class="goto"><a href="">去现场</a></div>
</div>
</div>
</div>
<div class="songContent fl">
<div class="songName clearfix" title=""><span class="audioName">酷狗音乐-就是歌多</span>
<a target="_blank" style="display:none" href="#" class="icon btnMv"></a>
</div>
<div class="songDetail clearfix">
<p class="albumName fl" style="display:none">
<span class="fontColor">专辑:</span>
<a target="_blank" href="" title="">未知专辑</a>
</p>
<p class="singerName fl" style="display:none">
<span class="fontColor">歌手:</span>
<a target="_blank" href="" title="">未知歌手</a>
</p>
</div>
<div class="displayNone">
</div>
<div class="songWordContent songWordContentM">
<!--div class="no_song">
<p class="nosong_tilte">暂无播放歌曲</p>
<p class="nosong_tip">你可以去酷狗网页添加歌曲</p>
<a class="goIndex" target="_blank" href="http://www.kugou.com/">去首页逛逛</a>
</div-->
</div>
</div>
</div>
<div class="blurBgMask"></div>
<div id="blurBg"></div>
</div>
<!--加载flash播放插件-->
<div id="fobj" class="fobj">
<object id="AudioPlayer3" name="AudioPlayer3" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10.0.32" width="100%" height="100%">
<param name="movie" value="https://www.kugou.com/yy/static/swf/AudioPlayer3.swf">
<param name="flashvars" value="useNewAPI=true&type=mp3&playstart=playStart&playcomplete=playOver&playopen=playOpen&JSPositioningPlay=JSPositioningPlay&flashinit=flashloaded&getSongData=getSongData&consolefun=consolefun&errorTips=errorTips">
<param name="quality" value="high">
<param name="allowScriptAccess" value="always">
<param name="allowNetworking" value="all">
<param name="wmode" value="transparent">
<param name="allowFullScreen" value="true">
<embed id="AudioPlayer3" name="AudioPlayer3" src="https://www.kugou.com/yy/static/swf/AudioPlayer3.swf" width="100%" height="100%" allowscriptaccess="always" allowNetworking="all" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="useNewAPI=true&type=mp3&playstart=playStart&playcomplete=playOver&playopen=playOpen&JSPositioningPlay=JSPositioningPlay&flashinit=flashloaded&getSongData=getSongData&consolefun=consolefun&errorTips=errorTips" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true">
</object>
</div>
<audio class="music" id="myAudio" src="">
<!-- <p class="myAudiohide">你的浏览器不支持<code>audio</code>标签.</p> -->
</audio>
<!-- 播放条 -->
<div class="audio-module playerbg" id="audioModule">
<div class="module-bg"></div>
<div class="player-module">
<!-- 模块左部分:上一首,播放,暂停,下一首 -->
<div class="controls-left">
<a class="icon icon-playbar-prev" id="prev"></a>
<a class="icon icon-playbar-play" id="toggle"></a>
<a class="icon icon-playbar-next" id="next"></a>
</div>
<!-- 专辑封面 -->
<div class="bar-albumImg">
</div>
<!-- 模块中间部分:容器 -->
<div class="controls-bar">
<!-- 模块中间部分:上半部分:歌曲信息 -->
<div class="song-info">
<!-- 歌曲名 -->
<div class="like-song">
<div class="controls-songName" title="">
<span class="songName" id="songName">酷狗音乐</span>
</div>
<pre class="songName" id="songNameTemp">酷狗音乐</pre>
</div>
<!-- 时长 -->
<div class="coding-duration">
<span class="duration ie8" id="duration"><i class="change-time"></i> / <i class="all-time"></i></span>
</div>
</div>
<!-- 模块中间部分:下半部分:播放控制条容器 -->
<div class="bar" id="bar">
<!-- 播放进度背景(自适应) -->
<div class="bg" id="progress_bg">
<span class="icon icon-playbar-bgleft" id="bg_left"></span>
<span class="bg-middle barBG" id="bg_middle"></span>
<span class="icon icon-playbar-bgright" id="bg_right"></span>
</div>
<!-- 播放进度条(自适应) -->
<div class="progress-bar" id="progress_bar">
<span class="icon icon-playbar-progressleft" id="progress_left"></span>
<div class="progress-middle" id="progress_middle">
<span class="progress barProgress" id="progress"></span>
</div>
</div>
<!-- 播放定位头(自适应) -->
<div class="drag-playhead" id="drag_playhead">
<span class="icon icon-playbar-playhead" id="playhead"></span>
</div>
</div>
</div>
<!-- 模块右部分:容器 -->
<div class="controls-right">
<!-- 模块右部分: 音量控制面板 -->
<div class="mode-volume-list">
<!-- 音量开关控制按钮 -->
<div class="volume-icon" id="volume">
<span class="icon icon-playbar-maxvox" id="volume_icon"></span>
</div>
<!-- 音量控制面板 -->
<div class="volume-panel" id="volume_panel">
<div class="volume-control" id="volume_control">
<span class="icon icon-playbar-progressbottom" id="volume_bottom"></span>
<div class="volume-bar" id="volume_bar">
<span class="volume-progress volumeProgress" id="volume_progress"></span>
</div>
<div class="volume-head" id="volume_head">
<span class="icon icon-playbar-volumehead" id="volumehead"></span>
</div>
</div>
</div>
<div class="play_tips">已添加到播放列表</div>
<!-- 播放模式 -->
<a class="icon icon-playbar-cycle" id="mode"></a>
<div class="mode-panel" id="mode_panel">
<ul>
<li>
<a class="loop mode-selected" id="loop" href="javascript:;" hidefocus="true">
<span class="icon icon-playbar-cycle active" id="loop_icon"></span>
<span class="loop-name" id="loop_name">列表循环</span>
</a>
</li>
<li>
<a class="single " id="single" href="javascript:;" hidefocus="true">
<span class="icon icon-playbar-singlecycle " id="single_icon"></span>
<span class="single-name" id="single_name">单曲循环</span>
</a>
</li>
<li>
<a class="random" id="random" href="javascript:;" hidefocus="true">
<span class="icon icon-playbar-randomcycle" id="random_icon"></span>
<span class="random-name" id="random_name">随机播放</span>
</a>
</li>
</ul>
</div>
<!-- 下载 -->
<a href="javascript:;" class="icon icon-playbar-download" id="pb_download" onclick="_hmt.push(['_trackEvent', 'song2software', 'song2download', 'song2kugou']);" ></a>
<!-- 分享 -->
<a href="javascript:;" onclick="_hmt.push(['_trackEvent', 'songshare', 'shareclick', 'sharekugou']);" class="icon icon-playbar-share" id="pb_share"></a>
<a class="icon list" id="list" href="javascript:;" hidefocus="true">
<span class="list-count" id="list_count"></span>
</a>
</div>
</div>
<div class="mod-playlist" id="mod-playlist" data-hide="true">
<div class="song-box">
<div class="box-header">
<div class="title">播放队列/<span></span></div>
<div class="action-box fr">
<span class="icon list-menu-icon-del clear" title="清空"></span>
<span class="line"></span>
<span class="icon list-menu-icon-close closePlayList" title="关闭播放队列"></span>
</div>
</div>
<div id="musicbox" class="musicbox ">
<div class="songjsAction">
<div class="noSongList">
<p class="noSongListTip">队列中还没有歌曲</p>
<p class="addSongLink">去<a target="_blank" href="https://www.kugou.com/" class="gotoIndex">首页</a>添加歌曲</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="showHide-playbar">
<span class="showHide-bg"></span>
<span class="icon show-playbar-btn" id="showHide_playbar"></span>
</div>
</div>
</div>
<div class="macDownload" id="macDownload">
<div class="macDownload-left">
<div class="macDownload-logo"></div>
<p class="macDownload-title">Mac版酷狗音乐已更新</p>
<p class="macDownload-txt">就是歌多</p>
</div>
<div class="macDownload-right">
<a class="macClick-up" target="_blank" href="https://itunes.apple.com/cn/app/%E9%85%B7%E7%8B%97%E9%9F%B3%E4%B9%90-%E5%B0%B1%E6%98%AF%E6%AD%8C%E5%A4%9A/id658741592?l=en&mt=12">详情</a>
<a class="macClick-down" target="_blank" href="https://download.kugou.com/download/kugou_mac">下载</a>
</div>
</div>
<iframe id="apply" style="display:none"></iframe>
<script>
var flag = 0, //flash 是否加载完毕
flashObj;//本地页面的falsh 对象
var kgPlay = {
// 是否支持audio
support_audio: function() {
return !!document.createElement('audio').canPlayType;
},
//获取flash对象
getFlashMovieObject: function(movieName) {
if (document[movieName]) {
return document[movieName];
} else if (navigator.appName.indexOf("Microsoft Internet") == -1) {
if (document.embeds && document.embeds[movieName]) {
return document.embeds[movieName];
}
} else if (window[movieName]) {
return window[movieName];
} else {
return document.getElementById(movieName);
}
},
// firefox获取flash
getSWF: function(name) {
var e = document.getElementById(name);
return (navigator.appName.indexOf("Microsoft") != -1) ? e : e.getElementsByTagName("embed")[0];
}
};
//表示flash加载完成,并初始化
function flashloaded() {
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1) {
flashObj = kgPlay.getSWF("AudioPlayer3");
} else {
flashObj = kgPlay.getFlashMovieObject("AudioPlayer3");
}
flag = 1;
}
</script>
<script data-embed="false" type="text/javascript" src="https://www.kugou.com/yy/static/js/play/lib/play_common.js" ></script>
<script src="https://staticssl.kugou.com/common/js/repalceHttpsImg.js"></script>
<script src="https://staticssl.kugou.com/common/js/min/login/kguser.v2.min.js"></script>
<script type="text/javascript">
var apmCollectData = apmCollectData || [];
if (kgPlay.support_audio()) {
flag = 0;
flashloaded = null;
// 删除flash
$("#fobj").remove();
var playbyAudio = document.createElement("script");
playbyAudio.charset = "UTF-8";
playbyAudio.src = "https://www.kugou.com/yy/static/js/play/playbyAudio.js?now="+new Date().getTime();
var byAudio = document.getElementsByTagName("script")[0];
byAudio.parentNode.insertBefore(playbyAudio, byAudio);
} else {
$(".myAudiohide").hide();
var playForFlash = document.createElement("script");
playForFlash.charset = "UTF-8";
playForFlash.src = "https://www.kugou.com/yy/static/js/play/playbyFlash.js?now="+new Date().getTime();
var byFlash = document.getElementsByTagName("script")[0];
byFlash.parentNode.insertBefore(playForFlash, byFlash);
}
</script>
<script type="text/javascript">
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?aedee6983d4cfc62f509129360d6bb3d";
var s = document.getElementsByTagName("head")[0];
s.parentNode.insertBefore(hm, s);
})();
(function() {
var apm = document.createElement("script");
apm.src = "https://staticssl.kugou.com/collect/common/dist/js/collect-2400.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(apm, s);
})();
</script>
<script src="https://staticssl.kugou.com/common/js-lib/min/kg-play-stat-report.es5.min.js"></script>
<script>
var observeDOM = (function() {
var MutationObserver =
window.MutationObserver || window.WebKitMutationObserver
return function(obj, callback) {
if (!obj || !obj.nodeType === 1) return // validation
if (MutationObserver) {
// define a new observer
var obs = new MutationObserver(function(mutations, observer) {
callback(mutations)
})
// have the observer observe foo for changes in children
obs.observe(obj, { childList: true, subtree: true })
} else if (window.addEventListener) {
obj.addEventListener('DOMNodeInserted', callback, false)
obj.addEventListener('DOMNodeRemoved', callback, false)
}
}
})()
window.__playStatReport = new PlayStatReport({ r: '酷狗电脑端官网', a: '', svar1: '歌曲' })
observeDOM(document, function() {
window.__hash &&
playStatReport.injectBaseParams({ hash: window.hash })
__playStatReport.startInjectStatReport()
})
</script>
</body>
</html>