当前位置: 代码迷 >> C# >> 获取qq音乐歌星的收听量(c#)
  详细解决方案

获取qq音乐歌星的收听量(c#)

热度:400   发布时间:2016-05-05 05:12:25.0
获取qq音乐歌手的收听量(c#)
也是闲着,看到我伦的qq音乐的收听量居然才520万,伤心。就抓下其他歌手的收听量,做个对比。

用到HtmlAgilityPack,Newtonsoft.Json

 1. [代码][C#]代码  

//设置listview的相关属性
listView1.GridLines = true;
listView1.View = View.Details;
listView1.LabelEdit = true;
listView1.Sorting = SortOrder.None;//排序,根据第一列
listView1.Columns.Add("歌手",100, HorizontalAlignment.Left);//参数:列名、宽度、对齐方式
listView1.Columns.Add("收听量", 300, HorizontalAlignment.Left);
2. [代码][C#]代码
WebClient wc = newWebClient();
            wc.Encoding = Encoding.UTF8;
            stringhtml = wc.DownloadString(newUri("http://y.qq.com/y/static/singer/index/all_hot_1.html"));
            HtmlAgilityPack.HtmlDocument doc = newHtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            stringnodexpath = "";
            //获取图片排序,10个人
            for(inti = 1; i < 11; i++)
            {
                nodexpath = String.Format("/html/body/div/div/div[2]/div/div[2]/ol/li[{0}]/h5/span[1]/a", i);
                HtmlNode base1 = doc.DocumentNode.SelectSingleNode(nodexpath);
                //获取歌手的id
                stringgetstr = base1.Attributes["href"].Value.Substring(21,14);
 
                WebClient wd = newWebClient();
                stringjsurl = String.Format("http://s.plcloud.music.qq.com/fcgi-bin/fcg_order_singer_getnum.fcg?singermid={0}&rnd=1420900900825&g_tk=974283127&loginUin=529324801&hostUin=0&format=jsonp&inCharset=GB2312&outCharset=gb2312&notice=0&platform=yqq&jsonpCallback=MusicJsonCallback&needNewCode=0", getstr);
                stringjsresult = wd.DownloadString(newUri(jsurl));
                jsresult = jsresult.Replace("MusicJsonCallback(","");
                intn = 0;
                n = jsresult.LastIndexOf(")");
                jsresult = jsresult.Substring(0, n);
                JObject jo = (JObject)JsonConvert.DeserializeObject(jsresult);
                 
                ListViewItem item = newListViewItem();
                item.Text = base1.InnerText;
                item.SubItems.Add(jo["num"].ToString());
                listView1.Items.AddRange(newListViewItem[] { item });
            }
            //获取文字排序,40个人
            for(inti = 1; i < 41; i++)
            {
                nodexpath = String.Format("/html/body/div/div/div[2]/div/div[3]/ol/li[{0}]/span[1]/a", i);
                HtmlNode base1 = doc.DocumentNode.SelectSingleNode(nodexpath);
                stringgetstr = base1.Attributes["href"].Value.Substring(21, 14);
 
                WebClient wd = newWebClient();
                stringjsurl = String.Format("http://s.plcloud.music.qq.com/fcgi-bin/fcg_order_singer_getnum.fcg?singermid={0}&rnd=1420900900825&g_tk=974283127&loginUin=529324801&hostUin=0&format=jsonp&inCharset=GB2312&outCharset=gb2312&notice=0&platform=yqq&jsonpCallback=MusicJsonCallback&needNewCode=0", getstr);
                stringjsresult = wd.DownloadString(newUri(jsurl));
                jsresult = jsresult.Replace("MusicJsonCallback(","");
                intn = 0;
                n = jsresult.LastIndexOf(")");
                jsresult = jsresult.Substring(0, n);
                JObject jo = (JObject)JsonConvert.DeserializeObject(jsresult);
 
                ListViewItem item = newListViewItem();
                item.Text = base1.InnerText;
                item.SubItems.Add(jo["num"].ToString());
                listView1.Items.AddRange(newListViewItem[] { item });

3. [图片] 新建位图图像.bmp  



  相关解决方案