码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-01-11 14:51:59      阅读:444      评论:0      收藏:0      [点我收藏+]

标签:

也是闲着,看到我伦的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 = new WebClient();
            wc.Encoding = Encoding.UTF8;
            string html = wc.DownloadString(new Uri("http://y.qq.com/y/static/singer/index/all_hot_1.html"));
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            string nodexpath = "";
            //获取图片排序,10个人
            for (int i = 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
                string getstr = base1.Attributes["href"].Value.Substring(21,14);
 
                WebClient wd = new WebClient();
                string jsurl = 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);
                string jsresult = wd.DownloadString(new Uri(jsurl));
                jsresult = jsresult.Replace("MusicJsonCallback(","");
                int n = 0;
                n = jsresult.LastIndexOf(")");
                jsresult = jsresult.Substring(0, n);
                JObject jo = (JObject)JsonConvert.DeserializeObject(jsresult);
                 
                ListViewItem item = new ListViewItem();
                item.Text = base1.InnerText;
                item.SubItems.Add(jo["num"].ToString());
                listView1.Items.AddRange(new ListViewItem[] { item });
            }
            //获取文字排序,40个人
            for (int i = 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);
                string getstr = base1.Attributes["href"].Value.Substring(21, 14);
 
                WebClient wd = new WebClient();
                string jsurl = 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);
                string jsresult = wd.DownloadString(new Uri(jsurl));
                jsresult = jsresult.Replace("MusicJsonCallback(", "");
                int n = 0;
                n = jsresult.LastIndexOf(")");
                jsresult = jsresult.Substring(0, n);
                JObject jo = (JObject)JsonConvert.DeserializeObject(jsresult);
 
                ListViewItem item = new ListViewItem();
                item.Text = base1.InnerText;
                item.SubItems.Add(jo["num"].ToString());
                listView1.Items.AddRange(new ListViewItem[] { item });

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

技术分享
技术分享

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

标签:

原文地址:http://blog.csdn.net/u012374012/article/details/42610951

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!