搜索引擎

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
请问: 实现如下的功能应该怎么做?
我想在自己的程序中封装一个搜索引擎(例如Google)的页面,然后根据用户事先提供的关键字,用代码实现“把关键字写入文本框,选定搜索方式,然后点击搜索按钮”的过程,应该怎么做?
其实我要实现的功能就是根据关键字显示搜索的结果,是否还有可以实现功能的更好思路?请指教。谢谢
就是直接使用http协议啊!
象我自己做了一个在我的家乡的BBS刷屏的机器……
这样做:
先定义:
char MyStr[65535]="POST /cgi-bin/xybook/bbs.cgi HTTP/1.1da"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*da"
"Referer: 127.0.0.1da"
"Accept-Language: zh-cnda"
"Content-Type: application/x-www-form-urlencodedda"
"Accept-Encoding: gzip, deflateda"
"User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)da"
"Host: www.xy.gz.cnda"
"Content-Length: 255da"
"Connection: Keep-Aliveda";
char strBuffer[9000];
//////////////////////////////////////////
然后:
AddStr = ("PUT http://202.98.201.244/cgi-bin/xybook/bbs.cgi?menu=addtitle&id=" +
Id + "&username=" + UserName.c_str() + "&userpsd=" + UserPsd.c_str()
+ "&mail=" + Mail.c_str() + "&home=" + Home.c_str() + "&emote=" + Emote.c_str()
+ "&titles=" + TitleEdit->Text.c_str() + "&comment=" + tempStr.c_str() + "");//cgi程序的提交形式
strcpy(MyStr,AddStr.c_str());
SendMyMessage();//这个函数见下:
 
bool __fastcall TMainForm::SendMyMessage(void)
{
WSADATA ws;
SOCKET s;
struct sockaddr_in addr;
int iResult;
long lResult;
flag = true;
lResult = WSAStartup(0x0101,&ws);
s = socket(AF_INET,SOCK_STREAM,0);
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
addr.sin_addr.s_addr = inet_addr ("202.98.201.244");
iResult=connect(s,(struct sockaddr *) &addr, sizeof(addr));
if(SOCKET_ERROR == iResult){// 连接失败
WSACleanup();
ShowMessage("连接服务器失败!!!请检查网络是否畅通!");
return false;
}else{// 连接成功
iResult = send(s,MyStr,sizeof(MyStr),0);
do
{
strset(strBuffer,' ');
iResult = recv(s,strBuffer,sizeof(strBuffer),0);
if(flag == true){
if(AnsiPos("<META HTTP-EQUIV=Refresh", AnsiString(strBuffer))<=0){
ShowMessage("错误!发送失败!请检查你的配置!比如密码和用户名等!");
Timer->Enabled = false;
}
flag = false;
}
Application->ProcessMessages();
}
while( iResult !=0 );
}
WSACleanup();
return true;
}
 
 
当然,这之前你要对你提交的被容先行处理:
AnsiString tempStr = ComMemo->Text;
tempStr = StringReplace(tempStr,'%',"%25",rf);
tempStr = StringReplace(tempStr,'=',"%3d",rf);
tempStr = StringReplace(tempStr,'&',"%26",rf);
tempStr = StringReplace(tempStr,'/',"%5c",rf);
tempStr = StringReplace(tempStr,'/',"%2f",rf);
tempStr = StringReplace(tempStr,'?',"?",rf);
tempStr = StringReplace(tempStr,'',"%0a",rf);
tempStr = StringReplace(tempStr,'',"%0d",rf);
tempStr = StringReplace(tempStr,' ',"%20",rf);
tempStr = StringReplace(tempStr,'<',"%3c",rf);
tempStr = StringReplace(tempStr,'>',"%3e",rf);
tempStr = StringReplace(tempStr,'#',"%23",rf);
tempStr = StringReplace(tempStr,'$',"%24",rf);
等等!
 

Similar threads

I
回复
0
查看
843
import
I
I
回复
0
查看
746
import
I
I
回复
0
查看
603
import
I
后退
顶部