在delphi 使用webbrowser如何取得网页的文字内容??感谢回复:

解决方案 »

  1.   

    获得IHTMLDocument2接口,然后就能获得了
      

  2.   

    why not use idhttp.get?
      

  3.   

    借问:
    //用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;//..........
    ---------------------------------------------- 
      

  4.   

    自己顶一下。难道在IE下面还有一个Frame,再下面才是Document ?
      

  5.   

    在网上搜到了如下内容:能否把这个翻译成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;
    }
      

  6.   

    奇怪,不是webbrowser.OleObject.document.body.innerText吗?