跳转到内容

User:DoraConan/機器人

维基百科,自由的百科全书

用戶頁 | 曾經創建的條目 | 我上傳的圖片 | 曾經創建的模版 | 機器人代碼收藏及機器人試驗區 | 沙盒 | 貢獻 | 對話頁

代碼1
#!/usr/bin/perl 
# catnav bot by WikiPedia:User:下一次登录 
# Sisclaimer: No warranty granted, use at your own risk! 
  
# call requirements 
use Getopt::Std; 
use LWP::Simple; 
use LWP::UserAgent; 
use HTTP::Request; 
use HTTP::Response; 
use HTTP::Cookies; 
  
#subroutine 
 
#parameters 
local $username="xcnbot";    #input your username here, only English names are tested. 
local $password="******";    #input your password here 
local $WIKI_PATH="zh.wikipedia.org"; 
local $WIKI_PAGE; 
 
### Login to wiki 
  
# Set up connection data 
my $browser=LWP::UserAgent->new(); 
my @ns_headers = ( 
 'User-Agent' => 'Xcnbot 1.0 by 下一次登录',  #Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20041107 Firefox/1.0', 
 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*', 
 'Accept-Charset' => 'iso-8859-1,*,utf-8', 
 'Accept-Language' => 'en-US', 
); 
  
# Hold cookies 
$browser->cookie_jar( {} ); 
  
{# Login 
    # Make login request 
    $response=$browser->post("http://".$WIKI_PATH."/w/index.php?title=Special:Userlogin&action=submitlogin", 
    @ns_headers, Content=>[wpName=>$username,wpPassword=>$password,wpRemember=>"1",wpLoginAttempt=>"Log in"]); 
  
    # After logging in, we should be redirected to another page. 
    # If we aren't, something is wrong. 
        if($response->code!=302) { #cannot login 
            print "We weren't able to login.\n\n"; 
            close(DEBUG); 
            exit 1; 
        } 
} 
 	print "Logged in \n"; 
 
 
# Trivial variables 
local $content; 
local $content1; 
local $content2; 
local @cnTree; 
local $editToken; 
local $editTime; 
 
 
# Set parameters 
local $DEPTH=5; #predefined DEPTH 
local $cChange=0; #Counter of CHANGEs 
my $vName; #Variable: current cat NAME 
my $vNameU="%E9%A0%81%E9%9D%A2%E5%88%86%E9%A1%9E";  #vName: Unicode, starting from “页面分类” 
my @aTree; #Array: current cat-TREE 
my $vDepth=0; #Variable: current cat-tree DEPTH 
my @aChild; #Array: current cat's CHILDREN    
my @aChildU; #aChildren: Unicode    
  
# Connect to root cat 
  $WIKI_PAGE=$vNameU; 
  $URL="http://".$WIKI_PATH."/wiki/Category:".$WIKI_PAGE; 
  $response=$browser->get($URL, @ns_headers); 
  $content=$response->as_string; 
    
  {  # extract vName 
   $filestartstr="<h1 class=\"firstHeading\">Category:"; 
   $filestart=index($content, $filestartstr);  
   $content1=substr($content, $filestart+34); 
        
   $fileendstr="</h1>"; 
   $fileend=index($content1, $fileendstr);   
   $vName=substr($content1, 0, $fileend); 
  }  # extract vName 
 
   print "got vName\n"; 
 
 # Change @aTree 
 $aTree[$vDepth]=$vName; 
 $vDepth+=1; 
  
 if(1)  
 { #debug 
	open INPUT, ">debug1.txt"; 
	print INPUT $URL; 
	print INPUT "\n\n before digui\n\n"; 
  close INPUT; 
 } #debug 
 
	if(1)  
	  { #log 
 		  open INPUT, ">cnlog.txt"; 
		 	print INPUT "program start\n"; 
			close INPUT; 
		} #log    	 
  
 &gotocat($vName, $vNameU, $vDepth, @aTree); 
  
 
sub gotocat 
{ #递归程序 
  my($vName, $vNameU, $vDepth, @aTree) = @_; 
     	if(1)  
		  { #debug log 
 			  open INPUT, ">diguilog.txt"; 
			 	print INPUT "Name="; 
		 		print INPUT $vName; 
			 	print INPUT "  UName="; 
		 		print INPUT $vNameU; 
			 	print INPUT "  vDepth="; 
			 	print INPUT "  aTree="; 
		 		print INPUT $vDepth; 
		 		for($i=0;$i<$vDepth;$i+=1) 
		 		{ 
		 			print INPUT $aTree[$i]; 
		 			print INPUT ">"; 
		 		} 
			 	print INPUT "\n"; 
				close INPUT; 
			} #debug log    	 	 
 
  my @aChild; 
  my @aChildU; 
  my $nChild=0; #Child cat number 
 
	if($vDepth>$DEPTH)  
	{ #depth exceeds 
		$aTree[1]="..."; 
		for($i=2;$i<$DEPTH;$i+=1) 
		{ 
			$aTree[$i]=$aTree[$i+1]; 
		} 
		$vDepth=$DEPTH; 
		 
     	if(1)  
		  { #debug log 
 			  open INPUT, ">>diguilog.txt"; 
			 	print INPUT "Depth exceeds\n"; 
				close INPUT; 
			} #debug log    	 	 
	} 
	 
	print "in digui. vDepth="; 
	print $vDepth; 
	print "\n"; 
 
 
   
  if(1) 
  { # list and sort all children 
    ## list 
    print "list "; 
     
    $WIKI_PAGE=$vNameU; 
    $URL="http://".$WIKI_PATH."/wiki/Category:".$WIKI_PAGE; 
    $response=$browser->get($URL, @ns_headers); 
    $content=$response->as_string; 
  
 		$content1=$content; 
    $filestartstr="<a class=\"CategoryTreeLabel  CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/wiki/Category:"; 
 
    while(index($content1, $filestartstr)>=0)  
    { #while there is more children 
			print "c "; 
			 
     {  # extract a Child cat line 
      $filestartstr="<a class=\"CategoryTreeLabel  CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/wiki/Category:"; 
      $filestart=index($content1, $filestartstr);  
      $content1=substr($content1, $filestart+99); 
           
      $fileendstr="</a></div>"; 
      $fileend=index($content1, $fileendstr);   
      $content2=substr($content1, 0, $fileend); 
      $content1=substr($content1, $fileend+10); 
     }  # extract a Child cat line    
 
     { # cat name and Uname 
     	$fileendstr="\">"; 
     	$fileend=index($content2, $fileendstr);   
     	$aChildU[$nChild]=substr($content2, 0, $fileend); 
     	$aChild[$nChild]=substr($content2, $fileend+2); 
     } # cat name and Uname 
     
     $nChild+=1; 
    } #while there is more children 
		 
   if(0) { ## check if there is "next 200" 
     $filestartstr="<br style=\"clear:both;\"/>"; 
   	 $filestart=index($content, $filestartstr); 
   	 $content1=substr($content, $filestart+25); 
   	 $fileendstr="<h2>"; 
   	 $fileend=index($content1, $fileendstr);   
   	 $content1=substr($content1, 0, $fileend); 
   	 $filestartstr="200</a>)<div id"; 
 
   	 while(index($content1, $filestartstr)>=0) 
   	 {	# while there is "next 200" 
	   	 print "200 "; 
			  
	 		{	## extract url 
 	   	  $filestartstr="200) (<a href=\""; 
		   	$filestart=index($content1, $filestartstr); 
		  	$content1=substr($content1, $filestart+15); 
		    $fileendstr="\" title="; 
    	  $fileend=index($content1, $fileendstr); 
      	$WIKI_PAGE=substr($content1, 0, $fileend); 
    	} ## extract url 
 
			$URL="http://".$WIKI_PATH.$WIKI_PAGE; 
			if(1)  
			  { #log 
		 		  open INPUT, ">>cnlog.txt"; 
				 	print INPUT $URL; 
				 	print INPUT "\n"; 
					close INPUT; 
				} #log    	 
			 
	    $response=$browser->get($URL, @ns_headers); 
	    $content=$response->as_string; 
	    $content1=$content; 
	    $filestartstr="<a class=\"CategoryTreeLabel  CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/wiki/Category:"; 
	    while(index($content1, $filestartstr)>=0)  
	    { #while there is more children 
	    	print "c "; 
 		    { # extract a Child cat line 
			    $filestartstr="<a class=\"CategoryTreeLabel  CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/wiki/Category:"; 
 		  	  $filestart=index($content1, $filestartstr);  
      		$content1=substr($content1, $filestart+99); 
           
      		$fileendstr="</a></div>"; 
		      $fileend=index($content1, $fileendstr);   
    		  $content2=substr($content1, 0, $fileend); 
		      $content1=substr($content1, $fileend+10); 
    		} # extract a Child cat line    
       
	      { # cat name and Uname 
		     	$fileendstr="\">"; 
		     	$fileend=index($content2, $fileendstr);   
		     	$aChildU[$nChild]=substr($content2, 0, $fileend); 
		     	$aChild[$nChild]=substr($content2, $fileend+2); 
		    } # cat name and Uname 
		     
		     $nChild+=1; 
		  } #while there is more children 
 
      # next 200? 
    	$filestartstr="<br style=\"clear:both;\"/>"; 
    	$filestart=index($content, $filestartstr); 
    	$content1=substr($content, $filestart+25); 
   	  $fileendstr="<h2>"; 
    	$fileend=index($content1, $fileendstr);   
    	$content1=substr($content1, 0, $fileend); 
   	  $filestartstr="200</a>)<div id"; 
   	 }	# while there is "next 200" 
			    	 
 	 } ## check if there is "next 200" 
   
   ## sort 
   	print "sort "; 
   	 
  	my $i,$j; 
  	my $swap; 
  	for($i=0;$i<$nChild-1;$i+=1) 
  	{ 
  		for($j=$i+1;$j<$nChild;$j+=1) 
  		{ 
  			if($aChild[$i] gt $aChild[$j]) 
  			{ 
  				$swap=$aChild[$i]; 
  				$aChild[$i]=$aChild[$j]; 
  				$aChild[$j]=$swap; 
 
  				$swap=$aChildU[$i]; 
  				$aChildU[$i]=$aChildU[$j]; 
  				$aChildU[$j]=$swap; 
  			} 
  		} 
  	} 
  	 
  	print "entered current page. nChild="; 
  	print $nChild; 
  	print "\n"; 
  	 
	  if(0)  
	  { #debug 
			 open INPUT, ">>debug1.txt"; 
			 my $i; 
			 for($i=0;$i<$nChild;$i+=1) 
			 { 
			 	print INPUT $aChild[$i]; 
			 	print INPUT "  "; 
			 	print INPUT $aChildU[$i]; 
			 	print INPUT "\n"; 
			 } 
		   print INPUT "\n\n\n"; 
			 close INPUT; 
		} #debug    	 
  } # list and sort all children 
 
	if(1)  
	  { #log 
 		  open INPUT, ">>cnlog.txt"; 
		 	print INPUT "Digui: Cat="; 
		 	print INPUT $vName; 
		 	print INPUT ", Tree="; 
		 	for($i=0;$i<$vDepth;$i+=1) 
		 	{  
		 		print INPUT $aTree[$i]; 
		 		print INPUT ">"; 
		 	} 
		 	print INPUT "\n"; 
		 	print INPUT "    "; 
		 	print INPUT $nChild; 
		 	print INPUT " children: "; 
		 	for($i=0;$i<$nChild;$i+=1) 
		 	{  
		 		print INPUT $aChild[$i]; 
		 		print INPUT " "; 
		 	} 
		 	print INPUT "\n"; 
			close INPUT; 
		} #log    	 
 
  
	my $i; 
	for($i=0;$i<$nChild;$i+=1)  
  { # check and add catnav to all children 
  	my $cnDepth; 
  	my $bFound=0;	#found same tree? 
  	my $bSame=1;	#cat name is the same? 
  	my $cnFound=0; 
		# get edit content 
			$WIKI_PAGE=$aChildU[$i]; 
			#$WIKI_PAGE="%E4%BA%9A%E6%B4%B2%E5%9B%BD%E5%AE%B6"; 
    	$URL="http://".$WIKI_PATH."/w/index.php?title=Category:".$WIKI_PAGE."&action=edit"; 
    	$response=$browser->get($URL, @ns_headers); 
    	$content=$response->as_string; 
   		  
    	# Get EditToken 
    	($editToken) = ( $content =~ m/value\=\"([0-9a-f\\]*)\" name\=\"wpEditToken\"/ ); 
    	($editTime) = ( $content =~ m/value\=\"([0-9a-f]*)\" name\=\"wpEdittime\"/ ); 
  		  
    	$filestartstr="<textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" id=\"wpTextbox1\" rows='25'"; 
    	$fileendstr="</textarea>"; 
    	$filestart= index($content, $filestartstr); 
    	$filestart+=92; 
    	$fileend= index($content, $fileendstr); 
    	$content=substr($content, $filestart, $fileend-$filestart); 
     
    # check if there is Catnav 
   	$filestartstr="{{Catnav|"; 
   	$content1=$content; 
    while(index($content1, $filestartstr)>=0) 
    { #while there is still Catnav 
    	$cnFound=1; 
	   	$cnDepth=0; 
    	$filestart=index($content1, $filestartstr); 
    	$content1=substr($content1, $filestart+9); 
    	$fileendstr="}}"; 
    	$fileend=index($content1, $fileendstr); 
    	$content2=substr($content1, 0, $fileend); 
    	$content1=substr($content1, $fileend+1); 
 
			$filestartstr="|"; 
			while(index($content2, $filestartstr)>=0) 
			{ #while there is | 
				$filestart=index($content2, $filestartstr); 
				$cnTree[$cnDepth]=substr($content2, 0, $filestart); 
				$content2=substr($content2, $filestart+1); 
				$cnDepth+=1; 
			} #while there is | 
			#the last one 
			$cnTree[$cnDepth]=$content2; 
			$cnDepth+=1; 
 
		if(0)  
	  { #debug 
			 open INPUT, ">>debug1.txt"; 
			 my $j; 
				for($j=0;$j<$cnDepth;$j+=1)  
			  { # check and add catnav to all children 
					 	 
					 { 
					 	print INPUT $cnTree[$j]; 
					 	print INPUT "  "; 
					 } 	 
					 	print INPUT "\n\n\n"; 
			  	 
				} # check and add catnav to all children 
		} #debug 
		 
		$bSame=1;  
		if($vDepth == $cnDepth) 
		{ 
			for($j=0;$j<$cnDepth;$j+=1)  
			{ 
				if($cnTree[$j] ne $aTree[$j])	{ 
				$bSame=0;} 
			} 
		} 
		else 
		{ 
			$bSame=0; 
		} 
		 
		if($bSame) 
		{ 
			$bFound=1; 
		} 
 
   	$filestartstr="{{Catnav|"; 
    } #while there is still Catnav 
		 
		print "entered child page. bFound=";	 
		print $bFound;	 
		print "\n";	 
		 
		if($bFound<1) 
		{	# add new tree 
			my $treecontent; 
			$treecontent="{{Catnav"; 
			for($j=0;$j<$vDepth;$j+=1) 
			{ 
				$treecontent=$treecontent."|".$aTree[$j]; 
			} 
			if($cnFound) { 
				$treecontent=$treecontent."}}\n"; 
			} 
			else { 
				$treecontent=$treecontent."}}\n\n"; 
			} 
						 
			$content=$treecontent.$content; 
 
			$WIKI_PAGE=$aChildU[$i]; 
    	$URL="http://".$WIKI_PATH."/w/index.php?title=Category:".$WIKI_PAGE."&action=edit"; 
 
			#check for illegal characters 
			my $special_char; 
			 
			$special_char="""; #" 
			while(index($content, $special_char)>=0) { 
				substr($content, index($content, $special_char), length($special_char) ) ="\""; 
			} 
			$special_char="<"; #< 
			while(index($content, $special_char)>=0) { 
				substr($content, index($content, $special_char), length($special_char) ) ="<"; 
			} 
			$special_char=">"; #> 
			while(index($content, $special_char)>=0) { 
				substr($content, index($content, $special_char), length($special_char) ) =">"; 
			} 
			$special_char="&"; #& 
			while(index($content, $special_char)>=0) { 
				substr($content, index($content, $special_char), length($special_char) ) ="&"; 
			} 
			 
			if(1) {#Update 
        $response=$browser -> 
          post($URL, @ns_headers, Content_Type=>'form-data',Content=> 
           [  wpTextbox1 => $content, 
		          wpSummary => "[[User:xcnbot|xcnbot]] testing", 
              wpSave => "Save page", 
              wpSection => "", 
              wpEdittime => $editTime, 
              wpEditToken => $editToken, 
              wpMinoredit => "1", 
              ]);	 
      print "Change made\n"; 
       
     	if(1)  
		  { #log 
 			  open INPUT, ">>cnlog.txt"; 
			 	print INPUT "    Child:"; 
		 		print INPUT $aChild[$i]; 
		 		print INPUT " change made.\n"; 
				close INPUT; 
			} #log    	 
	 
    	} #Update 
		} 
    		 
	} # check and add catnav to all children 
    
  # call sub-gotocat on every child 
  my $ch; 
 	for($ch=0;$ch<$nChild;$ch+=1)  
 	{ 
  	# Change @aTree 
     	if(1)  
		  { #log 
 			  open INPUT, ">>cnlog.txt"; 
			 	print INPUT "Go into: Child="; 
		 		print INPUT $aChild[$ch]; 
		 		print INPUT "\n"; 
				close INPUT; 
			} #log    	 	 
	  $aTree[$vDepth]=$aChild[$ch]; 
		&gotocat($aChild[$ch], $aChildU[$ch], $vDepth+1, @aTree); 
     	if(1)  
		  { #log 
 			  open INPUT, ">>cnlog.txt"; 
			 	print INPUT "Jump outto: Parent="; 
		 		print INPUT $vName; 
		 		print INPUT "\n"; 
				close INPUT; 
			} #log    	 	 
		 
	} 
} #递归程序
代碼2
#!/usr/bin/perl 
# catnav bot by WikiPedia:User:下一次登录 
# Disclaimer: No warranty granted, use at your own risk! 
  
# call requirements 
use Getopt::Std; 
use LWP::Simple; 
use LWP::UserAgent; 
use HTTP::Request; 
use HTTP::Response; 
use HTTP::Cookies; 
  
#subroutine 
 
#parameters 
local $username="xcnbot";    #input your username here, only English names are tested. 
local $password="******";    #input your password here 
local $WIKI_PATH="zh.wikipedia.org"; 
local $WIKI_PAGE; 
 
### Login to wiki 
  
# Set up connection data 
my $browser=LWP::UserAgent->new(); 
my @ns_headers = ( 
 'User-Agent' => 'Xcnbot1.0 by 下一次登录',  #Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20041107 Firefox/1.0', 
 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*', 
 'Accept-Charset' => 'iso-8859-1,*,utf-8', 
 'Accept-Language' => 'en-US', 
); 
  
# Hold cookies 
$browser->cookie_jar( {} ); 
 
{# Login 
    # Make login request 
    $response=$browser->post("http://".$WIKI_PATH."/w/index.php?title=Special:Userlogin&action=submitlogin", 
    @ns_headers, Content=>[wpName=>$username,wpPassword=>$password,wpRemember=>"1",wpLoginAttempt=>"Log in"]); 
  
    # After logging in, we should be redirected to another page. 
    # If we aren't, something is wrong. 
        if($response->code!=302) { #cannot login 
            print "We weren't able to login.\n\n"; 
            close(DEBUG); 
            exit 1; 
        } 
 	print "Logged in \n"; 
} 
 
# Trivial variables 
local $content; #target page content 
local $editcontent; #target edit content 
local $neweditcontent; #modified target edit content 
local $content1; #parent category content 
local $editToken; 
local $editTime; 
 
local $beforeCatnav; 
local @Catnav; 
local $afterCatnav; 
local $bError; 
local $vLine; 
local $nDepth; 
local $nCatnav; 
local @vCat; 
local $bChange; 
 
# Set parameters 
my $vNameU="%E5%BE%8C%E7%87%95%E5%B9%B4%E8%99%9F"; 
 
# get a list of categories from special:allpages  
 
my $article_count=0; #number of articles in allpages 
my @article_name;	#the characters of the article names for log 
my @article_unicode; #the unicode article names for connection 
my $last_string; #the unicode of the last article in the last run (init="%21") 
my $article_line; #one article line in allpage content 
my $article_ID;  
 
open LOG1, ">>log.txt"; 
 
while(1) { #process 
 
	#read last_string.txt and start allpages from that article 
	open FILE, "<last_string.txt"; 
	$last_string=""; 
	while (<FILE>) { 
  	  $last_string.=$_; 
	} 
 
	if(1) { #process allpages contents and make a list 
		#go to allpages and get the contents 
		$URL="http://".$WIKI_PATH."/w/index.php?title=Special:Allpages&from=".$last_string."&namespace=14"; 
		$response=$browser->get($URL, @ns_headers); 
		$filename1=$response->as_string; 
		$article_count=0; #reset the article count 
		 
		{	#truncate the contents 
			#find the start point and extract the content 
			$filestartstr="<table style=\"background: inherit;\" border=\"0\" width=\"100%\">"; 
			$filestart=index($filename1, $filestartstr);   
			$filename1=substr($filename1, $filestart+60); 
			 
			#find the end point and cut 
			$fileendstr="<div class=\"printfooter\">"; 
			$fileend=index($filename1, $fileendstr);   
			$filename1=substr($filename1, 0, $fileend); 
	 
		} #truncate the contents 
		 
		{ #find all the cat names 
			#extract a line (between<td> </td>)and leave rest to $filename1 
			$filestartstr="<td>"; 
			$fileendstr="</td>"; 
			$filestart=index($filename1, $filestartstr)+4; 
			$fileend=index($filename1, $fileendstr); 
			$article_line=substr($filename1, $filestart, $fileend-$filestart); 
			$filename1=substr($filename1, $fileend+5); 
		 
			while($article_count<=202)	{	#if there is article names in allpage contents 
	 
					#process $article_line 
						#extract the unicode name 
						$filestartstr="<a href=\"/wiki/"; 
						$filestart=index($article_line, $filestartstr)+15+9; 
						$article_line=substr($article_line, $filestart); 
						$fileendstr="\""; 
						$fileend=index($article_line, $fileendstr); 
						$article_unicode[$article_count]=substr($article_line, 0, $fileend); 
						$article_line=substr($article_line, $fileend+1); 
						 
						#extract the character name 
						$filestartstr="title=\""; 
						$filestart=index($article_line, $filestartstr)+7; 
						$article_line=substr($article_line, $filestart); 
						$fileendstr="\""; 
						$fileend=index($article_line, $fileendstr); 
						$article_name[$article_count]=substr($article_line, 0, $fileend); 
					 
						$article_count+=1; 
	 
				#extract a line (between<td> </td>)and leave rest to  
				$filestartstr="<td>"; 
				$fileendstr="</td>"; 
				$filestart=index($filename1, $filestartstr)+4; 
				$fileend=index($filename1, $fileendstr); 
				$article_line=substr($filename1, $filestart, $fileend-$filestart); 
				$filename1=substr($filename1, $fileend+5); 
				 
			}	#while  
		} #find all the cat names 
	} #process allpages contents and make a list 
	 
	$article_ID=0; 
 
	while($article_ID<$article_count) { #go through all the pages and process 
	 
	$vNameU=$article_unicode[$article_ID]; 
# Connect to root cat 
  $WIKI_PAGE=$vNameU; 
  $URL="http://".$WIKI_PATH."/wiki/Category:".$WIKI_PAGE; 
  $response=$browser->get($URL, @ns_headers); 
  $content=$response->as_string; 
	 
	print "\n"; 
	print $URL;  
	print LOG1 "\n"; 
	print LOG1 $URL;  
	 
 	$URL="http://".$WIKI_PATH."/w/index.php?title=Category:".$WIKI_PAGE."&action=edit"; 
 	$response=$browser->get($URL, @ns_headers); 
 	$editcontent=$response->as_string; 
   		  
 	# Get EditToken 
 	($editToken) = ( $editcontent =~ m/value\=\"([0-9a-f\\]*)\" name\=\"wpEditToken\"/ ); 
  ($editTime) = ( $editcontent =~ m/value\=\"([0-9a-f]*)\" name\=\"wpEdittime\"/ ); 
  		  
  $filestartstr="<textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" id=\"wpTextbox1\" rows='25'"; 
  $fileendstr="</textarea>"; 
  $filestart= index($editcontent, $filestartstr); 
  $filestart+=92; 
  $fileend= index($editcontent, $fileendstr); 
  $editcontent=substr($editcontent, $filestart, $fileend-$filestart); 
	$afterCatnav=$editcontent; 
	 
	print "\nC "; 
	print LOG1 "\nC "; 
 	$bChange=0; 
 	 
 	#organize edit content for catnav 
	$filestartstr="{{catnav";  
	$neweditcontent=$editcontent; 
	while(index($neweditcontent, $filestartstr)>=0) { 
			substr($neweditcontent, index($neweditcontent, $filestartstr), length($filestartstr) ) ="{{Catnav"; 
	} 
 
  #find all {{catnav 
	$filestartstr="{{Catnav";  
	$nCatnav=0; 
	while(index($neweditcontent, $filestartstr)>=0)  
	{ #find all {{catnav 
		$filestartstr="{{Catnav"; 
		$neweditcontent=substr($neweditcontent, index($neweditcontent, $filestartstr)); 
		$filestartstr="}}"; 
		$Catnav[$nCatnav]=substr($neweditcontent, 0, index($neweditcontent, $filestartstr)+2); 
		$neweditcontent=substr($neweditcontent, index($Catnav, $filestartstr)+2); 
		 
		$nCatnav+=1; 
		$filestartstr="{{Catnav";  
	} #find all {{catnav 
	 
  print $nCatnav; 
  print "cn(s) "; 
  print LOG1 $nCatnav; 
  print LOG1 "cn(s) "; 
     
  # process catnav  
  $nCatnav=0; 
  $filestartstr="title=\"catnav\" style="; 
  while(index($content, $filestartstr)>=0) 
  { # process catnav 
   	 
   	{# process catnav 
   		#get a line 
	   	$filestartstr="title=\"catnav\" style="; 
	   	$filestart=index($content, $filestartstr); 
	   	$content=substr($content, $filestart+21); 
 
	  	$fileendstr="</div>"; 
	   	$fileend=index($content, $fileendstr);   
	   	$vLine=substr($content, 0, $fileend); 
	   	$content=substr($content, $fileend+5); 
 
	   	#get all links 
	   	$filestartstr="..."; 
	   	if(index($vLine, $filestartstr)>=0) 
	   	{ 
	   		$filestart=index($vLine, $filestartstr); 
	   		$vLine=substr($vLine, $filestart+3); 
	   	} 
	   	 
	   	$nDepth=0; 
	   	$filestartstr="<a href=\"/wiki/Category:"; 
	   	while(index($vLine, $filestartstr)>=0) 
	   	{ #while there is a cat link 
		   	$filestartstr="<a href=\"/wiki/Category:"; 
		   	$filestart=index($vLine, $filestartstr)+24; 
		   	$vLine=substr($vLine, $filestart); 
 
		   	$filestartstr="\" title=\"Category:"; 
		   	$filestart=index($vLine, $filestartstr); 
		   	$vCat[$nDepth]=substr($vLine, 0, $filestart); 
		   	$vLine=substr($vLine, $filestart+18); 
 
		   	$nDepth+=1; 
	   	} #while there is a cat link 
	   
	  }# process catnav 
    	 
	   	#check parent cats 
	   	$bError=0; 
 			local $Page; 
 			$Page=$vNameU; 
	   	while($nDepth>0) 
	   	{ 
	   		$nDepth=$nDepth-1; 
	   		if($bError==0) 
	   		{ 
				  $WIKI_PAGE=$Page; 
				  $URL="http://".$WIKI_PATH."/wiki/Category:".$WIKI_PAGE; 
				  $response=$browser->get($URL, @ns_headers); 
  				$content1=$response->as_string; 
	   			 
	   			$filestartstr="<div id=\"catlinks\"><p class='catlinks'><a href=\"/wiki/Special:Categories\" title="; 
	   			$content1=substr($content1, index($content1, $filestartstr)); 
	   			$filestartstr="</span></p></div>"; 
	   			$content1=substr($content1, 0, index($content1, $filestartstr)); 
	   			 
	   			$Page=$vCat[$nDepth]; 
					my $Page1; 
	   			$Page1="Category:".$vCat[$nDepth]."\" title"; 
					 
	   			if(index($content1, $Page1)<0) 
	   			{ 
	   				$bError=1; 
	   				print "Err "; 
	   				print LOG1 "Err "; 
	   			} 
	   			 
	   		} 
	   	} 
	   	 
	   	#delete catnav   	 
	   	if($bError>0) 
	   	{ #delete catnav 
				my $cnstring="{{catnav|"; 
	  		substr($editcontent, index($editcontent, $cnstring), length($cnstring) ) ="{{Catnav|"; 
	  		substr($editcontent, index($editcontent, $Catnav[$nCatnav]), length($Catnav[$nCatnav])+1 ) =""; 
				$bChange=1; 
	   	} #delete catnav 
 		  
 		 $filestartstr="title=\"catnav\" style="; 
     $nCatnav+=1; 
  } # process catnav 
 
 	#update 
	if($bChange>0) 
	{	 
	   		 
	   		{ #check for illegal characters 
				my $special_char; 
				 
				$special_char="""; #" 
				while(index($neweditcontent, $special_char)>=0) { 
					substr($neweditcontent, index($neweditcontent, $special_char), length($special_char) ) ="\""; 
				} 
				$special_char="<"; #< 
				while(index($neweditcontent, $special_char)>=0) { 
					substr($neweditcontent, index($neweditcontent, $special_char), length($special_char) ) ="<"; 
				} 
				$special_char=">"; #> 
				while(index($neweditcontent, $special_char)>=0) { 
					substr($neweditcontent, index($neweditcontent, $special_char), length($special_char) ) =">"; 
				} 
				$special_char="&"; #& 
				while(index($neweditcontent, $special_char)>=0) { 
					substr($neweditcontent, index($neweditcontent, $special_char), length($special_char) ) ="&"; 
				} 
				$special_char=" "; #  
				while(index($neweditcontent, $special_char)>=0) { 
					substr($neweditcontent, index($neweditcontent, $special_char), length($special_char) ) =" "; 
				} 
			  } #check for illegal characters 
 
		$WIKI_PAGE=$vNameU; 
    $URL="http://".$WIKI_PATH."/w/index.php?title=Category:".$WIKI_PAGE."&action=edit"; 
						 
			if(1) {#Update 
        $response=$browser -> 
          post($URL, @ns_headers, Content_Type=>'form-data',Content=> 
           [  wpTextbox1 => $editcontent, 
		          wpSummary => "Testing: Wrong catnav deleted.", 
              wpSave => "Save page", 
              wpSection => "", 
              wpEdittime => $editTime, 
              wpEditToken => $editToken, 
              wpMinoredit => "1", 
              ]);	 
 
      print "Changed."; 
      print LOG1 "Changed."; 
    }  
 
  } 
  		 
  			 
	$article_ID+=1; 
	 
	} #while ID<count 
	 
	if(1)	{	#record last string.txt 
		open INPUT, ">last_string.txt"; 
		print INPUT $article_unicode[$article_count-1]; 
		close INPUT; 
	} 
	 
} #while whole