用到的jar包
jsoup-1.11.2.jar
json-20140107.jar
接口是QQ音乐的 解析是百度搜索到的
https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?is_xml=0&format=jsonp&key=歌曲名
仅供参考 :
//输入搜索的歌名
Scanner in = new Scanner(System.in);
String name = in.next();
List midList = new ArrayList();
try {
Document doc = Jsoup
.connect("https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?is_xml=0&format=jsonp&key="+name)
.get();
JSONObject jsonObject = new JSONObject(doc.body().html());
if(jsonObject.getInt("code") != -4){
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONObject("song").getJSONArray("itemlist");
for (int i = 0; i
JSONObject jsob = (JSONObject) jsonArray.get(i);
System.out.println(jsob.getString("name").toString());
midList.add(jsob.getString("mid").toString());
}
}else{
System.out.println("没有找到此歌曲 检查歌曲名或者歌手是否正确");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(midList != null){
for (String mid : midList) {
try {
String json = Jsoup.connect("https://www.sinsyth.com/lxapi/ssk/qqmusic.php")
.data("surl","https://y.qq.com/n/yqq/song/"+ mid +".html")
.data("strkey","qq_Music17_jiexi")
.userAgent(" Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0")
.timeout(5000)
.post()
.body()
.text();
JSONObject json1 = new JSONObject(json);
System.out.println(json1.getJSONObject("Rendata").getString("songURL"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
您看此文用·秒,转发只需1秒呦
领取专属 10元无门槛券
私享最新 技术干货