首页 新闻 会员 周边

.NET抓取土豆视频地址。求解。

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-03-29 11:14

http://www.tudou.com/playlist/playindex.do?lid=11542629&iid=76277106视频地址中,抓取到http://www.tudou.com/l/K5zq7guPnWw/&iid=76277106/v.swf播放器。两个地址为同一个视频。求大神。

问题补充: 解决完毕!
假扮天使的主页 假扮天使 | 初学一级 | 园豆:30
提问于:2011-03-29 09:58
< >
分享
所有回答(2)
0
public VideoHelper()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
///<summary>
/// 获取youku视频
///</summary>
///<param name="url"></param>
///<returns></returns>
public static Videoinfo getTudouVideo(string url){

WebClient web = new WebClient();
byte[] by = web.DownloadData(url);
string result = Encoding.GetEncoding("GB2312").GetString(by, 0, by.Length);
int beginLocal = result.IndexOf("<script>document.domain");
int endLocal = result.IndexOf("</script>");
string title = result.Substring(beginLocal, endLocal);
Videoinfo video = new Videoinfo();
video.Title = result;
video.Pic = "";
video.Flashsrc = "";
return video;
}
///<summary>
/// 获取ku6视频
///</summary>
///<param name="url"></param>
///<returns></returns>
public static Videoinfo getKu6Video(string url)
{

WebClient web = new WebClient();
byte[] by = web.DownloadData(url);
string result = Encoding.GetEncoding("gb2312").GetString(by, 0, by.Length);
HtmlDocument doc = HtmlDocument.Create(result, true);
/**
* 获取视频地址
*/
HtmlElement flashEt = doc.GetElementById("outSideSwfCode");
string flash = flashEt.Attributes["value"].Value;
string title = "";
HtmlElement[] elems = doc.GetElementsByTagName("meta").ToArray();
for (int i = 0; i < elems.Length; i++)
{
if (elems[i].Attributes["name"] != null)
{
if (elems[i].Attributes["name"].Value == "title")
{
title = elems[i].Attributes["content"].Value;
}
}
}
/**
* 获取视频缩略图
*/
HtmlElement picEt = doc.GetElementById("plVideosList");

string pic = null;
if(picEt!=null){
pic = picEt.GetElementsByTagName("img")[0].Attributes["src"].Value;
}else{
pic=doc.GetElementByClass(doc,"s_pic")[0].Attributes["src"].Value;
}
Videoinfo video = new Videoinfo();
video.Title = title;
video.Pic = pic;
video.Flashsrc = flash;
return video;

}
///<summary>
///
///</summary>
///<param name="url"></param>
///<returns></returns>
public static Videoinfo getyoukuvideo(string url)
{
WebClient web = new WebClient();
byte[] by = web.DownloadData(url);
string result = Encoding.GetEncoding("utf-8").GetString(by, 0, by.Length);
HtmlDocument doc = HtmlDocument.Create(result, true);

string title = "";
HtmlElement[] elems = doc.GetElementsByTagName("meta").ToArray();
for (int i = 0; i < elems.Length; i++)
{
if (elems[i].Attributes["name"] != null)
{
if (elems[i].Attributes["name"].Value == "title")
{
title = elems[i].Attributes["content"].Value;
}
}
}
/**
*获取视频缩略图
*/
string pic = doc.GetElementById("s_sina").Attributes["href"].Value;

int local = pic.IndexOf("pic=");
pic = pic.Substring(local + 4);
/**
* 获取视频地址
*/
string flash = doc.GetElementById("link2").Attributes["value"].Value;
Videoinfo video = new Videoinfo();
video.Title = title;
video.Pic = pic;
video.Flashsrc = flash;
return video;
}
///<summary>
///
///</summary>
///<param name="url"></param>
///<returns></returns>
public static Videoinfo get56Video(string url)
{
WebClient web = new WebClient();
byte[] by = web.DownloadData(url);
string result = Encoding.GetEncoding("utf-8").GetString(by, 0, by.Length);
HtmlDocument doc = HtmlDocument.Create(result, true);
string title = doc.TitleElement.Text.Replace(" -娱乐视频 在线观看 视频下载-56网视频","");
/**
* 获取视频缩略图
*/
int begin = result.IndexOf("\"img\":\"");
result = result.Substring(begin + 7, begin + 200);
int end = result.IndexOf("\"};");
string pic = result.Substring(0, end).Trim();
pic = pic.Replace("\\", "");

/**
* 获取视频地址
*/
int startpoint = url.LastIndexOf("/");
int endpoint = url.LastIndexOf(".html");
int urllength = url.Length;
string playername = url.Substring(startpoint, endpoint-startpoint);
string flash = "http://player.56.com" + playername+ ".swf";

Videoinfo video = new Videoinfo();
video.Title = title;
video.Pic = pic;
video.Flashsrc = flash;
return video;

}
///<summary>
/// 六间房视频
///</summary>
///<param name="url"></param>
///<returns></returns>
public static Videoinfo get6Video(string url)
{
WebClient web = new WebClient();
byte[] by = web.DownloadData(url);
string result = Encoding.GetEncoding("utf-8").GetString(by, 0, by.Length);
HtmlDocument doc = HtmlDocument.Create(result, true);
HtmlElement[] elems = doc.GetElementsByTagName("meta").ToArray();
string title = "";
for (int i = 0; i < elems.Length; i++)
{
if (elems[i].Attributes["name"] != null)
{
if (elems[i].Attributes["name"].Value == "description")
{
title = elems[i].Attributes["content"].Value;
}
}
}
HtmlElement picEt = doc.GetElementByClass(doc, "summary")[0];
string pic = picEt.GetElementsByTagName("img")[0].Attributes["src"].Value;
HtmlElement flashEt = doc.GetElementById("video-share-code");
string flashdoc= flashEt.Attributes["value"].Value;
HtmlDocument docm =HtmlDocument.Create(flashdoc,true);
string flash=docm.GetElementsByTagName("embed")[0].Attributes["src"].Value;
Videoinfo video = new Videoinfo();
video.Title = title;
video.Flashsrc = flash;
video.Pic = pic;
return video;

}
///<summary>
/// 判断是哪个网站的视频
///</summary>
///<param name="url"></param>
///<returns></returns>
public static Videoinfo getVideoInfo(String url)
{
Videoinfo video = new Videoinfo();

if (url.IndexOf("v.youku.com") != -1)
{
try
{
video = VideoHelper.getyoukuvideo(url);
}
catch (Exception e)
{
video = null;
}
}
else if (url.IndexOf("tudou.com") != -1)
{
try
{
video = VideoHelper.getTudouVideo(url);
}
catch (Exception e)
{
video = null;
}
}
else if (url.IndexOf("v.ku6.com") != -1)
{
try
{
video = VideoHelper.getKu6Video(url);
}
catch (Exception e)
{
video = null;
}
}
else if (url.IndexOf("6.cn") != -1)
{
try
{
video = VideoHelper.get6Video(url);
}
catch (Exception e)
{
video = null;
}
}
else if (url.IndexOf("56.com") != -1)
{
try
{
video = VideoHelper.get56Video(url);
}
catch (Exception e)
{
video = null;
}
}

return video;
}


抓取 =>正则=>所需的代码

万飞 | 园豆:215 (菜鸟二级) | 2011-11-11 14:28

大侠能否给我发一份抓取视频播放地址源代码啊,谢谢了!548301995@qq.com

支持(0) 反对(0) lezhan | 园豆:143 (初学一级) | 2011-12-09 12:08
0

你好,请问你这个问题的解决方法还有吗?HtmlDocument.Create直接提示我没有这个方法,285109823我的QQ能加一下吗啊?

王小喵0722 | 园豆:202 (菜鸟二级) | 2015-11-07 09:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册