哪位知道帮帮忙哈、、、、、

解决方案 »

  1.   

    获得网页源码
    http://expert.csdn.net/Expert/topic/1991/1991829.xml?temp=.9192163
    implementation
    uses shellapi,SHDocVw,activex;
    {$R *.dfm}function  WB_GetHTMLCode(WebBrowser:  TWebBrowser;  ACode:  TStrings):  Boolean;
    var
       ps:  IPersistStreamInit;
       ss:  TStringStream;
       sa:  IStream;
       s:  string;
    begin
       result:=false;
       ps  :=  WebBrowser.Document  as  IPersistStreamInit;
       s  :=  '';
       ss  :=  TStringStream.Create(s);
       try
           sa  :=  TStreamAdapter.Create(ss,  soReference)  as  IStream;
           try
           Result  :=  Succeeded(ps.Save(sa,  True));
           except
           end;
           if  Result  then  ACode.Add(ss.Datastring);
       finally
           ss.Free;
       end;
    end;//WB1.Navigate('http://cn.yahoo.com');
    procedure TForm1.Button3Click(Sender: TObject);
    begin
       if WB_GetHTMLCODE(WB1,memo1.Lines) then  ....
    end;
      

  2.   

    To:yang6130(沧海@月明) 这样获得的内容里,不包括网页中的框架的
      

  3.   

    这个代码支能够得到body里面的代码
      

  4.   

    function GetHTML(Document:IHTMLDocument2):String;
    var IDisp:IDispatch;
        pElement:IHTMLElement;
    begin
        for I := 0 to Document.all.length - 1 do    // Iterate
        begin
            IDisp:=Document.all.item(i,i);
            IDisp.QueryInterface(IID_IHTMLElement,pElement);
            if CompareText(pElement.tagName,'HTML')=0 then
            begin
                Result :=pElement.outerHTML;
                exit;
            end;
        end;    // for
    end;
      

  5.   

    我的代码可以得到整个HTML源代码。不过上面的有点问题,呵呵。掉了i的声明,重新写:
    function GetHTML(Document:IHTMLDocument2):String;
    var i:integer
        IDisp:IDispatch;
        pElement:IHTMLElement;
    begin
        for I := 0 to Document.all.length - 1 do    // Iterate
        begin
            IDisp:=Document.all.item(i,i);
            IDisp.QueryInterface(IID_IHTMLElement,pElement);
            if CompareText(pElement.tagName,'HTML')=0 then
            begin
                Result :=pElement.outerHTML;
                exit;
            end;
        end;    // for
    end;