关于取得网页文本(有源码) |
|
jean2004
初階會員 發表:69 回覆:80 積分:39 註冊:2004-12-18 發送簡訊給我 |
我用下面的代码取得网页文本,可是好多网页无法取得,现在上传源码和网页,请各位高手指点一二: void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString cbl,caddr;
HWND hCurrent,hChild,hWnd;
char szText[254],szcText[254],temp[100];
hWnd=FindWindow("IEFrame",NULL); GetClassName(hCurrent,temp,sizeof(temp));//
caddr="";
hChild=FindWindowEx(hWnd,0,"WorkerW",NULL);//NT
// hChild=FindWindowEx(hCurrent,0,"WorkerA",NULL);//98
hChild=FindWindowEx(hChild,0,"ReBarWindow32",NULL);
hChild=FindWindowEx(hChild, 0,"ComboBoxEx32",NULL);
hChild=FindWindowEx(hChild, 0,"ComboBox",NULL);
hChild=FindWindowEx(hChild, 0,"Edit",NULL);
int iLen=SendMessage(hChild,WM_GETTEXTLENGTH,0,0); //ShowMessage(iLen);
SendMessage(hChild,WM_GETTEXT,255,(long)szcText); caddr=(AnsiString)szcText;
//Edit1->Text=caddr;
CppWebBrowser1->Navigate(WideString(caddr)); //while(CppWebBrowser1->ReadyState!=Shdocvw_tlb::READYSTATE_COMPLETE) {
//Application->ProcessMessages();
//}
//CppWebBrowser1->OleObject->Document->CharSet='utf-8';
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,
LPDISPATCH pDisp, Variant *URL)
{
IHTMLDocument2 *HTMLDocument = NULL;
if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&HTMLDocument)))
{
IHTMLElement *pElement = NULL;
HTMLDocument->get_body(&pElement);
if (pElement)
{
WideString str;
pElement->get_innerText(&str);
RichEdit1->Text = AnsiString(str);
pElement->Release();
}
HTMLDocument->Release();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
RichEdit1->ScrollBars=ssVertical;//仅设置垂直滚动条
RichEdit1->WordWrap=true;//数据换行
Button1Click(Sender);
}
附加檔案:69270_我的软
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |