|
|
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;
#fff4fftine
#f5f5f1ters
local $username="xcnbot"; #ffffff your username here, only English names are tested.
local $password="******"; #ffffff 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 下一次登录', #ffffffa/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."http://zh.wikipedia.org/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) { #35ffff 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; #ff1210ined DEPTH
local $cChange=0; #f3fff1r of CHANGEs
my $vName; #f5ff54le: current cat NAME
my $vNameU="%E9%A0%81%E9%9D%A2%E5%88%86%E9%A1%9E"; #fff5f1: Unicode, starting from “页面分类”
my @aTree; #f5f5ff: current cat-TREE
my $vDepth=0; #f5ff54le: current cat-tree DEPTH
my @aChild; #f5f5ff: current cat's CHILDREN
my @aChildU; #53fff2ren: Unicode
# Connect to root cat
$WIKI_PAGE=$vNameU;
$URL="http://".$WIKI_PATH."/zh/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)
{ #21f4ff
open INPUT, ">debug1.txt";
print INPUT $URL;
print INPUT "\n\n before digui\n\n";
close INPUT;
} #21f4ff
if(1)
{ #ffffff
open INPUT, ">cnlog.txt";
print INPUT "program start\n";
close INPUT;
} #ffffff
&gotocat($vName, $vNameU, $vDepth, @aTree);
sub gotocat
{ #递归程序
my($vName, $vNameU, $vDepth, @aTree) = @_;
if(1)
{ #21f4ff 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;
} #21f4ff log
my @aChild;
my @aChildU;
my $nChild=0; #f3fff2 cat number
if($vDepth>$DEPTH)
{ #21ffff exceeds
$aTree[1]="...";
for($i=2;$i<$DEPTH;$i+=1)
{
$aTree[$i]=$aTree[$i+1];
}
$vDepth=$DEPTH;
if(1)
{ #21f4ff log
open INPUT, ">>diguilog.txt";
print INPUT "Depth exceeds\n";
close INPUT;
} #21f4ff 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."/zh/wiki/Category:".$WIKI_PAGE;
$response=$browser->get($URL, @ns_headers);
$content=$response->as_string;
$content1=$content;
$filestartstr="<a class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/zh/wiki/Category:";
while(index($content1, $filestartstr)>=0)
{ #fffff1 there is more children
print "c ";
{ # extract a Child cat line
$filestartstr="<a class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/zh/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;
} #fffff1 there is more children
if(0) { ## check if there is "next 200"
$filestartstr="<br style=\"clear:both;\"http://zh.wikipedia.org/>";
$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)
{ #ffffff
open INPUT, ">>cnlog.txt";
print INPUT $URL;
print INPUT "\n";
close INPUT;
} #ffffff
$response=$browser->get($URL, @ns_headers);
$content=$response->as_string;
$content1=$content;
$filestartstr="<a class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/zh/wiki/Category:";
while(index($content1, $filestartstr)>=0)
{ #fffff1 there is more children
print "c ";
{ # extract a Child cat line
$filestartstr="<a class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\" href=\"/zh/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;
} #fffff1 there is more children
# next 200?
$filestartstr="<br style=\"clear:both;\"http://zh.wikipedia.org/>";
$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)
{ #21f4ff
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;
} #21f4ff
} # list and sort all children
if(1)
{ #ffffff
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;
} #ffffff
my $i;
for($i=0;$i<$nChild;$i+=1)
{ # check and add catnav to all children
my $cnDepth;
my $bFound=0; #f0fff2 same tree?
my $bSame=1; #35ffff 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."http://zh.wikipedia.org/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\"http://zh.wikipedia.org/ );
($editTime) = ( $content =~ m/value\=\"([0-9a-f]*)\" name\=\"wpEdittime\"http://zh.wikipedia.org/ );
$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)
{ #fffff1 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)
{ #fffff1 there is |
$filestart=index($content2, $filestartstr);
$cnTree[$cnDepth]=substr($content2, 0, $filestart);
$content2=substr($content2, $filestart+1);
$cnDepth+=1;
} #fffff1 there is |
#fff1ff last one
$cnTree[$cnDepth]=$content2;
$cnDepth+=1;
if(0)
{ #21f4ff
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
} #21f4ff
$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|";
} #fffff1 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."http://zh.wikipedia.org/w/index.php?title=Category:".$WIKI_PAGE."&action=edit";
#f313ff 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) {#ff25f1
$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)
{ #ffffff
open INPUT, ">>cnlog.txt";
print INPUT " Child:";
print INPUT $aChild[$i];
print INPUT " change made.\n";
close INPUT;
} #ffffff
} #ff25f1
}
} # 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)
{ #ffffff
open INPUT, ">>cnlog.txt";
print INPUT "Go into: Child=";
print INPUT $aChild[$ch];
print INPUT "\n";
close INPUT;
} #ffffff
$aTree[$vDepth]=$aChild[$ch];
&gotocat($aChild[$ch], $aChildU[$ch], $vDepth+1, @aTree);
if(1)
{ #ffffff
open INPUT, ">>cnlog.txt";
print INPUT "Jump outto: Parent=";
print INPUT $vName;
print INPUT "\n";
close INPUT;
} #ffffff
}
} #递归程序
代碼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;
#fff4fftine
#f5f5f1ters
local $username="xcnbot"; #ffffff your username here, only English names are tested.
local $password="******"; #ffffff 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 下一次登录', #ffffffa/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."http://zh.wikipedia.org/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) { #35ffff login
print "We weren't able to login.\n\n";
close(DEBUG);
exit 1;
}
print "Logged in \n";
}
# Trivial variables
local $content; #f5fff1 page content
local $editcontent; #f5fff1 edit content
local $neweditcontent; #fff2f0ed target edit content
local $content1; #f5f1ff 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; #fff4f1 of articles in allpages
my @article_name; #fff1ff characters of the article names for log
my @article_unicode; #fff1ff unicode article names for connection
my $last_string; #fff1ff unicode of the last article in the last run (init="%21")
my $article_line; #fff1ff article line in allpage content
my $article_ID;
open LOG1, ">>log.txt";
while(1) { #fff3f1s
#f152ff last_string.txt and start allpages from that article
open FILE, "<last_string.txt";
$last_string="";
while (<FILE>) {
$last_string.=$_;
}
if(1) { #fff3f1s allpages contents and make a list
#go to allpages and get the contents
$URL="http://".$WIKI_PATH."http://zh.wikipedia.org/w/index.php?title=Special:Allpages&from=".$last_string."&namespace=14";
$response=$browser->get($URL, @ns_headers);
$filename1=$response->as_string;
$article_count=0; #f1f1ff the article count
{ #ffff35te the contents
#f0f2ff 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);
#f0f2ff the end point and cut
$fileendstr="<div class=\"printfooter\">";
$fileend=index($filename1, $fileendstr);
$filename1=substr($filename1, 0, $fileend);
} #ffff35te the contents
{ #f0f2ff all the cat names
#f1ff53t 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
#fff3f1s $article_line
#f1ff53t the unicode name
$filestartstr="<a href=\"/zh/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);
#f1ff53t 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;
#f1ff53t 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);
} #fffff1
} #f0f2ff all the cat names
} #fff3f1s 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."/zh/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."http://zh.wikipedia.org/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\"http://zh.wikipedia.org/ );
($editTime) = ( $editcontent =~ m/value\=\"([0-9a-f]*)\" name\=\"wpEdittime\"http://zh.wikipedia.org/ );
$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;
#fff5ffze edit content for catnav
$filestartstr="{{catnav";
$neweditcontent=$editcontent;
while(index($neweditcontent, $filestartstr)>=0) {
substr($neweditcontent, index($neweditcontent, $filestartstr), length($filestartstr) ) ="{{Catnav";
}
#f0f2ff all {{catnav
$filestartstr="{{Catnav";
$nCatnav=0;
while(index($neweditcontent, $filestartstr)>=0)
{ #f0f2ff 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";
} #f0f2ff 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
#f1ffff 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);
#f1ffff all links
$filestartstr="...";
if(index($vLine, $filestartstr)>=0)
{
$filestart=index($vLine, $filestartstr);
$vLine=substr($vLine, $filestart+3);
}
$nDepth=0;
$filestartstr="<a href=\"/zh/wiki/Category:";
while(index($vLine, $filestartstr)>=0)
{ #fffff1 there is a cat link
$filestartstr="<a href=\"/zh/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;
} #fffff1 there is a cat link
}# process catnav
#f313ff parent cats
$bError=0;
local $Page;
$Page=$vNameU;
while($nDepth>0)
{
$nDepth=$nDepth-1;
if($bError==0)
{
$WIKI_PAGE=$Page;
$URL="http://".$WIKI_PATH."/zh/wiki/Category:".$WIKI_PAGE;
$response=$browser->get($URL, @ns_headers);
$content1=$response->as_string;
$filestartstr="<div id=\"catlinks\"><p class='catlinks'><a href=\"/zh/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 ";
}
}
}
#21f1f1 catnav
if($bError>0)
{ #21f1f1 catnav
my $cnstring="{{catnav|";
substr($editcontent, index($editcontent, $cnstring), length($cnstring) ) ="{{Catnav|";
substr($editcontent, index($editcontent, $Catnav[$nCatnav]), length($Catnav[$nCatnav])+1 ) ="";
$bChange=1;
} #21f1f1 catnav
$filestartstr="title=\"catnav\" style=";
$nCatnav+=1;
} # process catnav
#ff25f1
if($bChange>0)
{
{ #f313ff 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) ) =" ";
}
} #f313ff for illegal characters
$WIKI_PAGE=$vNameU;
$URL="http://".$WIKI_PATH."http://zh.wikipedia.org/w/index.php?title=Category:".$WIKI_PAGE."&action=edit";
if(1) {#ff25f1
$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;
} #fffff1 ID<count
if(1) { #f1f3f2 last string.txt
open INPUT, ">last_string.txt";
print INPUT $article_unicode[$article_count-1];
close INPUT;
}
} #fffff1 whole
|