其实很简单,不过写出来以后,发现采集很慢,不会ASP,所以也没有看懂别人的ASP的,希望知道的留下言,帮帮忙,谢谢了。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
public partial class admin_GetData : System.Web.UI.Page
{
ArrayList urls = new ArrayList();
ArrayList flashs=new ArrayList();
int ID;
int num;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] == null)
{
Response.Redirect("login.aspx");
}
}
//获取网页源代码
private string getCode(string url)
{
WebRequest wrequest = WebRequest.Create(url);
WebResponse wresponse = wrequest.GetResponse();
Stream resStream = wresponse.GetResponseStream();
StreamReader sr = new StreamReader(resStream, Encoding.UTF8);
string theCode = sr.ReadToEnd();
resStream.Close();
sr.Close();
return theCode;
}
//获取本专辑的视频个数
private void getNum(string codes)
{
string reg="视频: <span class=/"num/">//d+</span>";
Match mc = Regex.Match(codes, reg);
string s = Regex.Replace(mc.ToString(), @"[^/d]+", "");
num = Int32.Parse(s);
//Response.Write("<script>alert('" + s + "')</script>");
}
//获取视频ID
private void getID(string url)
{
string s = Regex.Replace(url, @"[^/d]+", "");
ID = Int32.Parse(s);
}
//抓取得播放页
private void getPlay(string codes)
{
string reg = @"http://v.youku.com/v_playlist/(/w*|/d*)+/.htm.";
Match mc = Regex.Match(codes, reg);
string url = mc.ToString();
url = url.Substring(0, url.Length - 6);
for (int i = 0; i < num; i++)
{
urls.Add(url + i.ToString() + ".html");
}
}
//从播放页获取flasH地址
private string getFlash(string url)
{
string reg = "var videoId2=/".+/"";
Match mc = Regex.Match(getCode(url), reg);
string s = mc.ToString();
s = s.Substring(14, s.Length - 15);
return s;
}
//设置FLASH
private void setFlash()
{
string s = "http://player.youku.com/player.php/Type/Folder/Fid/" + ID.ToString() + "/Ob/";
for (int i = 0; i < num; i++)
{
flashs.Add(s + i.ToString() + "/sid/" + getFlash(urls[i].ToString()) + "/v.swf");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string codes = getCode(this.TextBox1.Text);
this.getNum(codes);
this.getID(this.TextBox1.Text);
this.getPlay(codes);
this.setFlash();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num-1; i++)
{
sb.Append(flashs[i] + "|");
}
sb.Append(flashs[num - 1]);
this.TextBox2.Text = sb.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("addVideo.aspx?flashs=" + this.TextBox2.Text);
}
}