Last article, Java climbed netease cloud music singer all album information

According to the album Id to get all the song information in the album, song name, song Id (the most important is this), song album name, song copyright status, the rest of the information extraction

package com.ssm.jsoup.music; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ssm.utils.FileUtils; import org.jsoup.Connection; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * describe: ** @author WFD * @date 2019/08/27 */ public class WyySong {public static void describe: ** @author WFD * @date 2019/08/27 */ public class WyySong {public static void main(String[] args) {readFile();
    }

    public static void readFile() {
        try {
            FileReader fr = new FileReader(new File("g://ablumId.json")); Br = new BufferedReader(fr); br = new BufferedReader(fr); String albumIds;while((albumIds = br.readLine()) ! = null) { int albumId = Integer.parseInt(br.readLine()); String url ="https://music.163.com/album?id=" + albumId + "";
                getData(url, albumId);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void getData(String url, int albumId) {
        System.out.println(url);

        Document doc = null;
        try {
            doc = Jsoup.connect(url).userAgent("Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36")
                    .header("Accept"."text/html,application/xhtml+xml,application/xml; Q = 0.9, image/webp image/apng, * / *; Q = 0.8, application/signed - exchange; v=b3")
                    .header("Accept-Encoding"."gzip, deflate, br")
                    .header("Accept-Language"."zh-CN,zh; Q = 0.9, en. Q = 0.8")
                    .header("Cookie"."Ntes_nnid = 6 c5b87bd25a17a9fd9692580e5c94f78, 1565912650142; _ntes_nuid=6c5b87bd25a17a9fd9692580e5c94f78; _iuqxldmzr_=32; WM_TID=LDdg6Rcj9ENEBRFUUFc4pPF4%2B6vTAn2G; WM_NI=R9FV8%2B3KZYFzFTyT7isTQivbb2VLf%2FzcQWAi%2BQdwZbxir0FYRR17q5zGEaYaTxwuyNrXXwr8kuNyRC2wcdeCeCAMWeyd1e8YJR%2FyJPg1kc 3dMwiiFWuGVyQtxssnI3kBT04%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eed1cf4eacb8bb8ac641899e8fb3c85b928f8e84f333a7939790c14f8a90fdd3d92af0fea7c3b92a92e78ab7bb 21f19596bac572868cb7b5b663b18c9f8af56aa2ee9aade525babd9fb8c463e98fac98d96abcb7bed1c553928effd8f43fba998b82dc6b98a8b996fc 46b2889898f134a9ab829ad149f2a9ad85e849a79d8faed66fbbbcff86bb538a8ee19ac95ca5efa584b2708fa9a78ac55db7999a9ad480bcadbd8fcc 39a99e9cd1b737e2a3; JSESSIONID-WYYY=yBXBK%2FIFCVHGtcBTi3%5CSUeDQMvfzApFAMBZzlZ%2BENNt7n2f9j2SCTvBRQpFACIc5EnGK3%2BtFhTQJWOhtCkJvHZ8olJ83RYG8 Exukhj6Ftzw%2FBwylje03bjPW4Vl9IXXOHeNIRWxO4%2BKndGOJ0HjhnNZJtoESJht8PfF%2FfzAVXh6kOWiq%3A1566909226292")
                    .header("Referer"."https://music.163.com/discover/artist/cat?id=1001&initial=65")
                    .header("Upgrade-Insecure-Requests"."1")
                    .method(Connection.Method.GET)
                    .timeout(200000).get();

            Elements names = doc.select("#song-list-pre-data"); Elements singer = doc.select(".intr:eq(1) span a"); // album = document.select (".tit .f-ff2"); JSONArray JSONArray = jsonarray.parsearray (names.text());for (int i = 0; i < jsonArray.size(); i++) {
                String songName = jsonArray.getJSONObject(i).getString("name").replace("\" "."").replace("\ \"."");
                String songId = jsonArray.getJSONObject(i).getString("id");
                String songStatus = jsonArray.getJSONObject(i).getString("status");
                String mess = "{" +
                        "\"songName\":\"" + songName + "\"," +
                        "\"songId\":\"" + songId + "\"," +
                        "\"songStatus\":\"" + songStatus + "\"," +
                        "\"singer\":\"" + singer.text() + "\"," +
                        "\"singerId\":\"" + singer.attr("href").
                        replace("/artist? id="."") + "\"," +
                        "\"album\":\"" + album.text().replace("\" "."").replace("\ \"."") + "\"," +
                        "\"albumId\":\"" + albumId + "\" " +
                        "}";
                System.out.println(mess);
                FileUtils.saveConToFile(mess, "g://song1.json"); } } catch (Exception e) { // e.printStackTrace(); }}}Copy the code

Online and download songs on the sample link: music.163.com/song/media/…

Id is the id of the song that the above code crawls out