问题描述
<scriptlanguage="JavaScript"src="http://8234567.com/javascript.php?flag=djyzsua"></script>要采集的页面是这个该如何做,请告诉下,在线等速度结贴50
解决方案
解决方案二:
难道是这个?WebClientwc=newWebClient();Encodingenc=Encoding.GetEncoding("GB2312");//如果是乱码就改成utf-8/GB2312Byte[]pageData=wc.DownloadData("http://8234567.com/");//从资源下载数据并返回字节数组。stringhtml=enc.GetString(pageData);
解决方案三:
不是,这个是我的代码,你可以看下,不用WebClient要采集<scriptlanguage="JavaScript"src="http://8234567.com/javascript.php?flag=djyzsua"></script>的内容。以js形式保存,但是这样的项目我第一次做,所以,想请教高手看看,该怎么获取,我我要采集的页面的内容,因为其中包含了,javaScriptusingSystem;usingSystem.Collections.Generic;//usingSystem.Linq;usingSystem.Text;usingSystem.Net;usingSystem.IO;usingSgml;usingSystem.Xml;usingSystem.Data.OleDb;usingSystem.Collections;usingSystem.Timers;namespaceCatchDiv{classProgram{staticstringtoday="1-1";staticstringnews="1-1";staticList<string>list=newList<string>();publicstaticvoidshow(objectsender,EventArgsargs){today=DateTime.Now.Month.ToString()+"-"+DateTime.Now.Day.ToString();if(!list.Contains(today)){if(DateTime.Now.Hour==18/*&&DateTime.Now.Minute==1*/){//write();Console.WriteLine("成功添加"+today+"日的历史上的今天所存在的事件");list.Add(today);}//show(null,null);Console.ReadLine();//bbs的获取地址stringhtml=GetHtml("http://e.jznews.com.cn/indexmain/","id");//stringhtml=GetHtmlConsole.WriteLine(html);stringnames=DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();//stringpath=@"F:e-ms"+names+".js";stringpath=@"F:e-ms"+names+".html";System.IO.File.AppendAllText(path,html);Console.Read();}}//publicstaticvoidTimeDoing()//{//Timert=newTimer(10000);//t.Elapsed=newSystem.Timers.ElapsedEventHandler(Main);//t.AutoReset=true;//t.Enabled=true;//}///<summary>///捕获页面HTML代码///</summary>staticvoidMain(string[]args){System.Threading.Thread.Sleep(3000);Timertimer=newTimer();timer.Interval=6000;//一秒钟获取一次,timer.Elapsed+=newElapsedEventHandler(show);timer.Start();//show(null,null);Console.ReadLine();//bbs的获取地址stringhtml=GetHtml("http://8234567.com/javascript.php?flag=djyzsua/","src");//E-线民生的获取地址//stringhtml=GetHtml("http://e.jznews.com.cn/indexmain/","id");Console.WriteLine(html);stringname=DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();stringpath=@"F:bbs"+name+".js";//stringpath="document.write(""+name+"")";System.IO.File.AppendAllText(path,html);Console.Read();}publicstaticstringGetHtml(stringurl,stringbm){WebResponseresponse=null;Streamstream=null;StreamReaderreader=null;WebRequestrequest=WebRequest.Create(url);response=request.GetResponse();stream=response.GetResponseStream();try{reader=newStreamReader(stream,System.Text.Encoding.GetEncoding(bm));}catch{reader=newStreamReader(stream,System.Text.Encoding.GetEncoding("GB2312"));}stringpagehtml=reader.ReadToEnd();returnpagehtml;}