主要源码
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Web;
///////////////////////////////////////////////////////////////////////////// ////////////////////////////作者:kkkkyue//////////////////////////////////// ////////////////////////创建时间:2008年9月8日/////////////////////////////// ///////////////////////////////////////////////////////////////////////////// 
namespace SougouMp3Search

{
/// <summary>
/// MP3结构体
/// </summary>
public class Mp3Struck

{
/// <summary>
/// 歌名
/// </summary>
public string Name = "";

/// <summary>
/// 歌手名
/// </summary>
public string Author = "";

/// <summary>
/// 类型
/// </summary>
public string Type = "";

/// <summary>
/// 大小
/// </summary>
public string Size = "";

/// <summary>
/// SOGOU下载页面URL
/// </summary>
public string PageURI = "";

/// <summary>
/// 下载地址集合
/// </summary>
public ArrayList DownloadURI=
new ArrayList();

}

/// <summary>
/// MP3搜索
/// </summary>
public class Mp3Search

{
readonly WebClient wc =
new WebClient();

private const string _URL =
"http://mp3.sogou.com/music.so?as=false&w=02009900&_asf=mp3.sogou.com&_ast=1220904551";

private const string Dwordstr = "&query=";

private const string Dpage = "&page=";

//private const int count = 30;

/// <summary>
/// 通过关键字和页数获得SOGOU下载页面URL集合
/// </summary>
/// <param name="dWord"></param>
/// <param name="page"></param>
/// <returns></returns>
public string[] GetPageURIsByDword(string dWord, int page)
{
string Html = wc.DownloadString(_URL + Dwordstr + UrlEncode(dWord) + Dpage + page);
int count1 = 0;
int count2 = 0;
int count = 0;
while (count1 != -1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1 == -1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2 == -1)
{
break;
}
count++;
}
count1 = 0;
count2 = 0;

string[] mp3Strucks = new string[count];
count = 0;
while (count1 != -1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1 == -1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2 == -1)
{
break;
}
string td = Html.Substring(count1, count2 - count1);
mp3Strucks[count] = td;
count++;
}
return mp3Strucks;
}

/// <summary>
/// 通过关键字和页数获得MP3结构体集合
/// </summary>
/// <param name="dWord"></param>
/// <param name="page"></param>
/// <returns></returns>
public Mp3Struck[] GetListByDword(string dWord, int page)
{
string Html = wc.DownloadString(_URL + Dwordstr + UrlEncode(dWord) + Dpage + page);
int count1 = 0;
int count2 = 0;
int count = 0;
while (count1!=-1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1==-1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2==-1)
{
break;
}
count++;
}
count1 = 0;
count2 = 0;

Mp3Struck[] mp3Strucks = new Mp3Struck[count];
count = 0;
while (count1 != -1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1 == -1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2 == -1)
{
break;
}
string td = Html.Substring(count1, count2 - count1 );
mp3Strucks[count] = GetDownURI(td);
mp3Strucks[count].PageURI = td;
count++;
}
return mp3Strucks;
}


/// <summary>
/// 通过SOGOU下载页面获得MP3结构体
/// </summary>
/// <param name="downURI"></param>
/// <returns></returns>
public Mp3Struck GetDownURI(string downURI)
{
Mp3Struck mp3Struck=new Mp3Struck();
mp3Struck.PageURI = downURI;
string htm2 = "";
htm2 = wc.DownloadString("http://mp3.sogou.com/" + downURI);
int count1 = 0;
int count2 = 0;

count2 = htm2.IndexOf("歌名:<a", count2);
count1 = htm2.IndexOf(">", count2);
count2 = htm2.IndexOf("</a", count1);
mp3Struck.Name = htm2.Substring(count1 + 1, count2 - count1 - 1);

count2 = htm2.IndexOf("歌手:<a", count2);
count1 = htm2.IndexOf(">", count2);
count2 = htm2.IndexOf("</a", count1);
mp3Struck.Author = htm2.Substring(count1 + 1, count2 - count1 - 1);

count1 = htm2.IndexOf("格式:", count2);
count2 = htm2.IndexOf("</td>", count1);
mp3Struck.Type = htm2.Substring(count1 + 3, count2 - count1 - 3);

count1 = htm2.IndexOf("大小:", count2);
count2 = htm2.IndexOf("</td>", count1);
mp3Struck.Size = htm2.Substring(count1 + 3, count2 - count1 - 3);
while (count1 != -1)
{
count1 = htm2.IndexOf("http://", count2);
if (count1 == -1)
{
break;
}
count2 = htm2.IndexOf("\">", count1);
if (count2==-1)
{
break;
}
string td = htm2.Substring(count1, count2 - count1);
mp3Struck.DownloadURI.Add(td);
}
return mp3Struck;
}

private static string UrlEncode(string url)
{
return HttpUtility.UrlEncode(url, Encoding.GetEncoding("GB2312"));
}

}
}
整个类没什么特别有技术含量的东西,
提供了3个方法
public string[] GetPageURIsByDword(
string dWord,
int page)
public Mp3Struck[] GetListByDword(
string dWord,
int page)
public Mp3Struck GetDownURI(
string downURI)
第2方法是获取一个 MP3STRUCK的集合
MP3STRUCK是一个结构体用来保存MP3的各种信息 包括 歌手 歌名 下载地址 等等
但是由于这个方法一次要请求30多个 SOUGOU的页面 所以不推荐使用
第1个方法是返回歌曲下载链接的集合
第3个方法则可以通过返回的歌曲下载链接地址 获取MP3STRUCK
下面是利用片段
protected void Button1_Click(
object sender, EventArgs e)

{

SougouMp3Search.Mp3Search cl =
new Mp3Search();

SougouMp3Search.Mp3Struck[] mp3Strucks = cl.GetListByDword(TextBox1.Text.Trim(), Convert.ToInt32(TextBox2.Text.Trim()));
foreach (var struck
in mp3Strucks)

{

Response.Write(
"歌手:" + struck.Author +
"</br>");

Response.Write(
"歌名:" + struck.Name +
"</br>");

Response.Write(
"类型:" + struck.Type +
"</br>");

Response.Write(
"大小:" + struck.Size +
"</br>");
int count = 1;
foreach (var h
in struck.DownloadURI)

{

Response.Write(
"<a href=\""+h+
"\">下载"+count +
"</a></br>");

count++;

}

Response.Write(
"</br>");

}

}
转载于:https://blog.51cto.com/kkkkyue/98125