有些时候需要用程序检索网络上的数据,比如要取出特定网页上的特定文字等。。二话不说,直接上代码了
效果:
void __fastcall TFormMain::btn_1Click(TObject *Sender) { OutPutLog("正在获取网页数据...."); TMemoryStream *ms=new TMemoryStream; IdHTTP1->Get(g_Url,ms);//g_Url是网页网址 const int msSize=ms->Size; LPSTR lpBuf=new char[msSize]; ms->Position=0; ms->Read(lpBuf,msSize); delete ms; String const strText=String(lpBuf,msSize); delete [] lpBuf; OutPutLog("网页数据获取完毕,正在分析页面元素..."); String strFind,strTemp; const String strFindMark="TRIAL-"; int UserStartPos=strText.Pos(strFindMark); //找出这的位置 int UserLengh= 100; String UseInfoBlock= strText.SubString(UserStartPos,UserLengh).Trim(); String User=UseInfoBlock.SubString(1,14); E_user->Text=User; String PassWordMark="密 码: "; String PassWord=UseInfoBlock.SubString(UseInfoBlock.Pos(PassWordMark)+PassWordMark.Length(),10); E_passWord->Text=PassWord; }