在delphi 使用webbrowser如何取得网页的文字内容??感谢回复:
解决方案 »
- Image1再问一次
- quickrep打印一切正常,不过偶尔打印页数超过40张后,quickrep1.pre……预览的时候就会抛异常
- 请教Delphi7的时间函数
- 怎樣實現Delphi中不同分辯率下窗体中各物件的自動調整的实现!
- 求ADOQuery,ADOCommand,ADODataSet操作数据库的代码!
- 进来看看,delphi的这种设计是不是误导了用户的面向对象编程思想!
- 哪里有中文的Dephi联机帮助下???能提供Dephi的命名规范吗???
- 为什么动态菜单加入后不能显示?
- 能不能把panel控件设成在运行时可以用鼠标拖动!
- 获取服务器时间
- 如何得到合计最大值
- 现在哪个版本的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;
}