classProgram { Public Static voidMain (string[] args) { intI=0; String[] Urlarray=NewString[] {"http://www.baidu.com/","http://msdn.microsoft.com/","http://www.qidian.com/Default.aspx" }; RefreshPage Repa=NewRefreshPage (0,1, Urlarray,false); while(I <7) {Repa. Next (); Repa. Findcurrent="No"; I++; } } }
View Code
classRefreshPage {intcurrentpage; intNextPage; String[] Urlarray; PublicString findcurrent="No"; BOOLStop; PublicRefreshPage (intCurrentPage,intNextPage, string[] Urlarray,BOOLStop) { This. CurrentPage =currentpage; This. NextPage =NextPage; This. Urlarray =Urlarray; This. Stop =Stop; } Public voidNext () {shdocvw.shellwindows SW=Newshdocvw.shellwindows (); while(Findcurrent = ="No") { foreach(Shdocvw.internetexplorer IwebinchSW) { if(Iweb.LocationURL.StartsWith (Urlarray[currentpage])) {HTMLDocument doc2
= Iweb.document asHTMLDocument; Htmlscriptelement Script= (htmlscriptelement) doc2.createelement ("Script"); Script.text="function Newdoc (URL) {window.location.assign (URL)} t=settimeout (\ "Newdoc ("+"'"+ Urlarray[nextpage] +"'"+") \ ", ()"; HTMLBody Body= Doc2.body asHTMLBody; if(Body! =NULL{body.appendchild (ihtmldomnode) script); Findcurrent="Yes"; } Else Continue; } }} currentpage+=1; NextPage+=1; if(NextPage >=urlarray.length) NextPage=0; if(CurrentPage >=urlarray.length) CurrentPage=0; System.Console.WriteLine (" Current"); } }
View Code
1. First you need to reference two DLLs
SHDocVw.dll
Mshtml.dll
2. This example is given in the array, the array is stored in the URL that will be iterating, the program accesses the open Web page to look for the value matching the first URL of the array, and adds a script to it, so that the page jumps to another URL, that is,
The next value of the array, which iterates through all the URLs in the array.
3. Variable findcurrent is very important, because it takes time for the browser to open a Web page, and the program reads it, very quickly, if there is no judgment on the variable, the code will never read the URL that is currently being looked for.
while (findcurrent = = "No")
Similarly read to the current URL, but the HTML content has not been load finished, and can not read the body of the HTML, it will not be able to read the HTML body, the following judgment is also very important
if (Body! = null)