在delphi 使用webbrowser如何取得網頁的文字內容??
感謝回復:
uj5u.com熱心網友回復:
獲得IHTMLDocument2介面,然后就能獲得了uj5u.com熱心網友回復:
why not use idhttp.get?uj5u.com熱心網友回復:
借問://用delphi與網頁互動時出現的問題,ie.document沒有值。
//實作的功能是,自動點列印審批網頁里的同意按鈕。
var
Wnd: HWND;
WndChild:HWND;
doc:IHtmlDocument2;
IE: iwebbrowser2;
All: IHtmlElementCollection;
HtmlElement: IHtmlElement;
len,i:integer;
item:OleVariant;
begin
Wnd := FindWindow('IEFrame', '列印審批 - Windows Internet Explorer');
WndChild := FindWindowEx(Wnd, 0,'Frame Tab', nil);
WndChild := FindWindowEx(WndChild, 0,'TabWindowClass', nil );
WndChild := FindWindowEX(WndChild, 0, 'Shell DocObject View', nil);
WndChild := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);//找到'Internet Explorer_Server'類的句柄
if WndChild <> 0 then
begin
GetIEFromHWnd(WndChild, IE);
if(IE <>nil) then
begin
doc:=IE.Document as IHtmlDocument2;//這里就出錯了,doc得到的值是0,ie是有值的,不知何故。
//注:網頁是完成列印審批功能的,是動態生成的網頁,地址欄里有asp?,打開網頁源代碼一看,里面全部都是代碼。而換了其它非動態的網頁除錯時是可以運行的。
all:=doc.links ;
len:=all.length;
//..........
----------------------------------------------
uj5u.com熱心網友回復:
自己頂一下。難道在IE下面還有一個Frame,再下面才是Document ?uj5u.com熱心網友回復:
在網上搜到了如下內容:能否把這個翻譯成delphi,頭大!!!///////////////////////////////////////////////////////////////
IHTMLDocument2* GetDocFromFrame(IHTMLDocument2* pDoc2)
{
CComPtr<IHTMLDocument3> pDoc3;
CComPtr<IHTMLDocument2> pDoc2Frame;
hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;
if(hr==S_OK)
{
CComBSTR bstrName("FRAME");//CComBSTR bstrName("IFRAME");
CComPtr<IHTMLElementCollection> pElemCollFrame;
hr=pDoc3->getElementsByTagName(bstrName,&pElemCollFrame);
if (hr!=S_OK) return NULL;
long pLength;
hr=pElemCollFrame->get_length(&pLength);
if(hr!=S_OK) return NULL;
for(int i=0;i<pLength;i++)
{
IDispatch *pDispFrame=NULL;
CComVariant vIndex=i;
hr=pElemCollFrame->item(vIndex,vIndex,&pDispFrame);
if(hr!=S_OK) continue;
CComPtr<IHTMLElement> pElemFrame;
hr=pDispFrame->QueryInterface(IID_IHTMLElement,(void**)&pElemFrame);
if(hr!=S_OK) continue;
CComPtr<IHTMLFrameBase2> pFrameBase2;
hr=pElemFrame->QueryInterface(IID_IHTMLFrameBase2,(void**)&pFrameBase2);
if(hr!=S_OK) continue;
CComPtr<IHTMLWindow2> pWindow2;
hr=pFrameBase2->get_contentWindow(&pWindow2);
if(hr==S_OK)
{
hr=pWindow2->get_document(&pDoc2Frame);
if (hr==S_OK)
{
return pDoc2Frame;
}
}
}
pDispFrame->Release();
}
return NULL;
}
uj5u.com熱心網友回復:
奇怪,不是webbrowser.OleObject.document.body.innerText嗎?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/94538.html
標籤:網絡通信/分布式開發
上一篇:想獲取到TWebbrowser中打開網頁內訪問的所有檔案連接,包括javascript通過XMLHTTP訪問的網頁地址
