在delphi 使用webbrowser如何取得网页的文字内容??感谢回复:
解决方案 »
- 用DELPHI如何调用DESKTOPTODEVICE函数向PDA传送XML文件啊?
- dbgrid如何根据数据库的表的列名自动调整宽度?
- fastreport打印问题,预栏时页数疯狂增多,哪位大哥指点下。
- 我用PARADOX做数据库,用的BDE。现在要做安装程序,请问需要哪些BDE文件,听说还要在注册表中写什么?谁能指点一二?
- 如何将两个字符合并?
- 用 ClientDataSet 如何像query:的requestlive设置能够动态更改数据! 急
- ldhlyh(小菜一碟) 来拿分ldhlyh(小菜一碟) 来拿分
- 在程序运行阶段,如何改变一个常的值?
- 组件包里面的DLL,BPL两种文件怎么用
- 如何得到当前显示的鼠标光标的句柄和鼠标光标的热点?
- 如何得到合计最大值
- 现在哪个版本的Delphi比较好
//用delphi与网页交互时出现的问题,ie.document没有值。
//实现的功能是,自动点打印审批网页里的同意按钮。varWnd: 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;//..........
----------------------------------------------
///////////////////////////////////////////////////////////////
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;
}