HttpWebResponse response = null; HttpWebRequest request = null;
string wangzhi = this.textBox1.Text;
wangzhi="http://ts.lobit.cn/educa/unvisity/tvbit/g3shu.php";
request =WebRequest.Create(wangzhi) as HttpWebRequest;
request.Method = "POST";
byte[] buffer = Encoding.GetEncoding("GB2312").GetBytes("myid=caifu100178&pwd=2712120");
request.ContentLength = buffer.Length;
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Referer = "http://ts.lobit.cn/";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322";
CookieContainer container=new CookieContainer();
container.SetCookies(new Uri(wangzhi), "PHPSESSID=37c1125efc3e209172eb245cdfde1d65");
request.CookieContainer = container;
CredentialCache credCache = new CredentialCache();
NetworkCredential CRED = new NetworkCredential("caifu100178", "2712120");
credCache.Add(new Uri(wangzhi), "Basic", CRED);
Stream w = request.GetRequestStream();
w.Write(buffer, 0, buffer.Length); response = request.GetResponse() as HttpWebResponse;
Stream sr = response.GetResponseStream();
StreamReader s = new StreamReader(sr, Encoding.GetEncoding("gb2312"));
start: string jy = s.ReadToEnd();
int sindex=0, eindex=0, i=0;
for(i=0; i<1000;i++)
{
sindex=jy.IndexOf("rtsp://",sindex); if (sindex!=-1)
{
eindex = jy.IndexOf("rm", sindex, 100);
if (sindex!=-1 && eindex!=-1 && eindex>sindex)
{
string a = jy.Substring(sindex, eindex - sindex + 2);
DirectoryInfo MuLu =Directory.CreateDirectory("E:\\jiaoyu");
if(!MuLu.Exists)
{MuLu.Create();}
DirectoryInfo MuLus =Directory.CreateDirectory("E:\\jiaoyu\\"+wangzhi.Replace("http://ts.lobit.cn/educa/unvisity/tvbit/",""));
FileInfo myfile =new FileInfo("E:\\jiaoyu\\"+wangzhi.Replace("http://ts.lobit.cn/educa/unvisity/tvbit/","") +"\\wangzhi.txt");
StreamWriter sw = myfile.AppendText();
sw.WriteLine(a);
sw.Close();
sindex = sindex + 1;
}
}
else{
int xindex=0, yindex=0, j=0;
for(j=0; j< 1000;j++)
{
xindex = xindex + 1; xindex =( jy.IndexOf("href=\"",xindex) + "href=\"".Length);
yindex = jy.IndexOf("php", xindex, 15); if (yindex > xindex)
{
wangzhi = jy.Substring(xindex, yindex - xindex);
wangzhi = "http://ts.lobit.cn/educa/unvisity/tvbit/" + wangzhi + "php";
request =WebRequest.Create(wangzhi) as HttpWebRequest;
request.Method = "get";
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Referer = "http://ts.lobit.cn/member/index.php";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322";
CookieContainer container1=new CookieContainer();
container.SetCookies(new Uri(wangzhi), "PHPSESSID=37c1125efc3e209172eb245cdfde1d65");
request.CookieContainer = container1;Stream w1 = request.GetRequestStream();
response = request.GetResponse() as HttpWebResponse;
Stream sr1 = response.GetResponseStream();
StreamReader s1 = new StreamReader(sr, Encoding.GetEncoding("gb2312"));
goto start; } }
}我想从网站时的每个网页中包含的视频文件抓下来,当第一次POST帐号和密码和COOKIE上去,可以抓下内容来,然后转向下一个网页抓取,这时问题出现了,超时退出!不管是该网站什么地址,只要输进去,第一页总能抓下来,再继续抓第二页时,总是抓不下来!超时
有没有高手帮我分析一下,拜托!!!!!!!!!!!!!!
string wangzhi = this.textBox1.Text;
wangzhi="http://ts.lobit.cn/educa/unvisity/tvbit/g3shu.php";
request =WebRequest.Create(wangzhi) as HttpWebRequest;
request.Method = "POST";
byte[] buffer = Encoding.GetEncoding("GB2312").GetBytes("myid=caifu100178&pwd=2712120");
request.ContentLength = buffer.Length;
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Referer = "http://ts.lobit.cn/";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322";
CookieContainer container=new CookieContainer();
container.SetCookies(new Uri(wangzhi), "PHPSESSID=37c1125efc3e209172eb245cdfde1d65");
request.CookieContainer = container;
CredentialCache credCache = new CredentialCache();
NetworkCredential CRED = new NetworkCredential("caifu100178", "2712120");
credCache.Add(new Uri(wangzhi), "Basic", CRED);
Stream w = request.GetRequestStream();
w.Write(buffer, 0, buffer.Length); response = request.GetResponse() as HttpWebResponse;
Stream sr = response.GetResponseStream();
StreamReader s = new StreamReader(sr, Encoding.GetEncoding("gb2312"));
start: string jy = s.ReadToEnd();
int sindex=0, eindex=0, i=0;
for(i=0; i<1000;i++)
{
sindex=jy.IndexOf("rtsp://",sindex); if (sindex!=-1)
{
eindex = jy.IndexOf("rm", sindex, 100);
if (sindex!=-1 && eindex!=-1 && eindex>sindex)
{
string a = jy.Substring(sindex, eindex - sindex + 2);
DirectoryInfo MuLu =Directory.CreateDirectory("E:\\jiaoyu");
if(!MuLu.Exists)
{MuLu.Create();}
DirectoryInfo MuLus =Directory.CreateDirectory("E:\\jiaoyu\\"+wangzhi.Replace("http://ts.lobit.cn/educa/unvisity/tvbit/",""));
FileInfo myfile =new FileInfo("E:\\jiaoyu\\"+wangzhi.Replace("http://ts.lobit.cn/educa/unvisity/tvbit/","") +"\\wangzhi.txt");
StreamWriter sw = myfile.AppendText();
sw.WriteLine(a);
sw.Close();
sindex = sindex + 1;
}
}
else{
int xindex=0, yindex=0, j=0;
for(j=0; j< 1000;j++)
{
xindex = xindex + 1; xindex =( jy.IndexOf("href=\"",xindex) + "href=\"".Length);
yindex = jy.IndexOf("php", xindex, 15); if (yindex > xindex)
{
wangzhi = jy.Substring(xindex, yindex - xindex);
wangzhi = "http://ts.lobit.cn/educa/unvisity/tvbit/" + wangzhi + "php";
request =WebRequest.Create(wangzhi) as HttpWebRequest;
request.Method = "get";
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*";
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Referer = "http://ts.lobit.cn/member/index.php";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322";
CookieContainer container1=new CookieContainer();
container.SetCookies(new Uri(wangzhi), "PHPSESSID=37c1125efc3e209172eb245cdfde1d65");
request.CookieContainer = container1;Stream w1 = request.GetRequestStream();
response = request.GetResponse() as HttpWebResponse;
Stream sr1 = response.GetResponseStream();
StreamReader s1 = new StreamReader(sr, Encoding.GetEncoding("gb2312"));
goto start; } }
}我想从网站时的每个网页中包含的视频文件抓下来,当第一次POST帐号和密码和COOKIE上去,可以抓下内容来,然后转向下一个网页抓取,这时问题出现了,超时退出!不管是该网站什么地址,只要输进去,第一页总能抓下来,再继续抓第二页时,总是抓不下来!超时
有没有高手帮我分析一下,拜托!!!!!!!!!!!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货