📄 tsearchserver.cpp
字号:
pos=link.Find(cc); //pos=link.AnsiPos(cc);
}
}
FNextPageUrl=link;
return true;
}
//----------------------------------------------------
CString TSearchServer::GetNextPage(CString temp,CString key)
{
try {
CString str="",link="";
TAnalyseLink* FALink=new TAnalyseLink;
CopyCharacter();
FALink->Copy(FSUrlCharacter);
str=temp;
str=Translate(str);
link=FALink->ExtractLinkAndTitle(str,true,true);
FNextPageFlag=IsNext(&str,key) ;
delete FALink;
if (ClearLink.Find("@")!=-1) //if (ClearLink.AnsiPos("@")!=0)
link=ModifyLink(link);
if (ClearLink.Find("&")!=-1) //if (ClearLink.AnsiPos("&")!=0)
link=AdjustLink(link);
if (ClearLink.Find("#")!=-1) //if (ClearLink.AnsiPos("#")!=0)
link=AheadBrief(link);
if (!FSUrlCharacter.BaseLink.IsEmpty())
link=AddBaseLink(link);
return link;
}
catch(...) {
return "SearchError";
}
}
//-----------------------------------------------------
bool TSearchServer::GetNextPageFlag()
{
return FNextPageFlag;
}
//------------------------------------------------
CString TSearchServer::GetNextPageUrl()
{
return FNextPageUrl;
}
//---------------------------------------------------
CString TSearchServer::GetUrlAdress()
{
return FUrlAddress;
}
int TSearchServer::TotalRecords() {
return FTotalRecords;
}
//----------------------------------------------
CString TSearchServer::ExtractLink(CString temp)
{
CString link,title,SearchHref;
int pos=0,pos1=0,length=0;
pos=SearchKey.Find("&"); //pos=SearchKey.AnsiPos("&");
SearchHref=SearchKey.Mid(0,pos); //SearchHref=SearchKey.SubString(1,pos-1);
length=SearchHref.GetLength();
if (temp[length]=='"') { // if (temp[length+1]=='"')
temp.Delete(0,length+1); //temp=temp.Delete(1,length+1);
// temp.Delete(1,length+1); //temp=temp.Delete(1,length+1);
pos=temp.Find('"'); // pos=temp.AnsiPos('"');
if (pos<3) { //if (pos<4)
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('"'); //pos=temp.AnsiPos('"');
}
link=temp.Mid(0,pos); //link=temp.SubString(1,pos-1);
}
//else if (temp.SubString(length+1,1)=="'") {
else if (temp.Mid(length,1)=="'") {
temp.Delete(0,length+2); //temp=temp.Delete(1,length+1);
pos=temp.Find("'"); //pos=temp.AnsiPos("'");
if (pos<3) { //if (pos<4) {
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find("'"); //pos=temp.AnsiPos("'");
}
link=temp.Mid(0,pos ); //
}
//else if (temp.SubString(length+1,1)=="\\") {
else if (temp.Mid(length,1)=="\\") {
temp.Delete(0,length+2); // temp=temp.Delete(1,length+1);
pos=temp.Find("\\"); //pos=temp.AnsiPos("\\");
if (pos<3) { //if (pos<4)
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('"'); //pos=temp.AnsiPos('"');
}
link=temp.Mid(0,pos); //link=temp.SubString(1,pos-1);
}
else {
temp.Delete(0,length); //temp=temp.Delete(1,length);
pos=temp.Find(' '); //pos=temp.AnsiPos(' ');
pos1=temp.Find('>'); //pos1=temp.AnsiPos('>');
if (pos<4||pos==-1||pos>pos1) pos=pos1; //if (pos<4||pos==0||pos>pos1)
link=temp.Mid(0,pos ); //link=temp.SubString(1,pos-1);
}
// if (link[link.Length()]=='"') link=link.Delete(link.Length(),1);
if (link[link.GetLength()-1]=='"') link.Delete(link.GetLength()-1,1);
return link;
}
//----------------------------------------------
CString TSearchServer::ModifyLink(CString temp)
{
CString templink="";
int pos=temp.Find("简介:"); //int pos=temp.AnsiPos("简介:");
while (pos>-1) { // while (pos>0)
//templink=templink+temp.SubString(1,pos+5);
templink=templink+temp.Mid(0,pos+6);
temp.Delete(0,pos+6); //temp=temp.Delete(1,pos+5);
pos=temp.Find("简介:");//pos=temp.AnsiPos("简介:");
if (pos==-1) break; //if (pos==0) break;
temp.Delete(0,pos+6); //temp=temp.Delete(1,pos+5);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; //if (pos==0) break;
templink=templink+temp.Mid(0,pos+1); // templink=templink+temp.SubString(1,pos);
temp.Delete(0,pos+1); // temp=temp.Delete(1,pos);
pos=temp.Find("简介:"); //pos=temp.AnsiPos("简介:");
}
return templink;
}
CString TSearchServer::AdjustLink(CString temp)
{
CString templink="",linktitle="";
int pos=temp.Find('\n'); //int pos=temp.AnsiPos('\n');
while (pos>0) {
templink=Clear(temp.Mid(0,pos+1)); //templink=Clear(temp.SubString(1,pos));
linktitle=linktitle+templink;
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; // if (pos==0)
linktitle=linktitle+temp.Mid(0,pos+1); //linktitle=linktitle+temp.SubString(1,pos);
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; //if (pos==0)
linktitle=linktitle+temp.Mid(0,pos+1); //linktitle=linktitle+temp.SubString(1,pos);
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
}
return linktitle;
}
CString TSearchServer::Clear(CString temp)
{
// if (temp.SubString(1,4)=="http"|| temp.SubString(1,4)=="Http"
// ||temp.SubString(1,4)=="HTTP")
// temp=temp.Delete(1,4);
if (temp.Mid(0,4)=="http"|| temp.Mid(0,4)=="Http"
||temp.Mid(0,4)=="HTTP")
temp.Delete(0,4);
int pos=temp.Find("http"); //pos=temp.AnsiPos("http");
if (pos==-1) pos=temp.Find("Http"); // if (pos==0) pos=temp.AnsiPos("Http");
if (pos==-1) pos=temp.Find("HTTP");
temp.Delete(0,pos);
return temp;
}
//------------------------------
CString TSearchServer::AheadBrief(CString temp)
{
CString buffer,templink,brief;
int pos=temp.Find("简介:"); //int pos=temp.AnsiPos("简介:");
templink=temp.Mid(0,pos ); //templink=temp.SubString(1,pos-1);
temp.Delete(0,pos+6); //temp=temp.Delete(1,pos+5);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
while(pos>-1) { //while(pos>0)
buffer=temp.Mid(0,pos+1); //buffer=temp.SubString(1,pos);
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; //if (pos==0)
buffer=buffer+temp.Mid(0,pos+1); //buffer=buffer+temp.SubString(1,pos);
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; //if (pos==0)
brief=temp.Mid(0,pos+1); // brief=temp.SubString(1,pos);
templink=templink+brief+buffer;
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
}
return templink+"简介:"+'\n';
}
CString TSearchServer::Translate(CString str)
{
int pos;
pos=str.Find("Href"); //pos=str.AnsiPos("Href");
while(pos>-1) { // while(pos>0)
str.Insert(pos,"href"); //str=str.Insert("href",pos);
pos=str.Find("Href"); //pos=str.AnsiPos("Href");
str.Delete(pos,4); //str=str.Delete(pos,4);
pos=str.Find("Href"); //pos=str.AnsiPos("Href");
}
pos=str.Find("HREF"); //pos=str.AnsiPos("HREF");
while(pos>-1) { // while(pos>0)
str.Insert(pos,"href"); //str=str.Insert("href",pos);
pos=str.Find("HREF"); //pos=str.AnsiPos("HREF");
str.Delete(pos,4); //str=str.Delete(pos,4);
pos=str.Find("HREF"); //pos=str.AnsiPos("HREF");
}
pos=str.Find("</A>"); // pos=str.AnsiPos("</A>");
while(pos>-1) { //while(pos>0)
str.Insert(pos,"</a>"); //str=str.Insert("</a>",pos);
pos=str.Find("</A>"); //pos=str.AnsiPos("</A>");
str.Delete(pos,4); //str=str.Delete(pos,4);
pos=str.Find("</A>"); //pos=str.AnsiPos("</A>");
}
return str;
}
CString TSearchServer::AddBaseLink(CString temp)
{
CString templink="",baselink=FSUrlCharacter.BaseLink,link="";
int pos=temp.Find('\n'); //int pos=temp.AnsiPos('\n');
while(pos>-1) { //while(pos>0)
templink=temp.Mid(0,pos+1); //templink=temp.SubString(1,pos);
templink=baselink+templink;
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; //if (pos==0)
templink=templink+temp.Mid(0,pos+1); //templink=templink+temp.SubString(1,pos);
temp.Delete(0,pos+1); //temp=temp.Delete(1,pos);
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
if (pos==-1) break; //if (pos==0)
templink=templink+temp.Mid(0,pos+1); //templink=templink+temp.SubString(1,pos);
temp.Delete(0,pos+1); // temp=temp.Delete(1,pos);
link=link+templink;
pos=temp.Find('\n'); //pos=temp.AnsiPos('\n');
}
return link;
}
/////////////////////////////////////////////////////////////////////////////
// TSearchServer message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -