标签:
也是闲着,看到我伦的qq音乐的收听量居然才520万,伤心。就抓下其他歌手的收听量,做个对比。用到HtmlAgilityPack,Newtonsoft.Json
//设置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);
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¬ice=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¬ice=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 });
标签:
原文地址:http://blog.csdn.net/u012374012/article/details/42610951