比如说我想保存http://www.163.com首页的网页的源文件,用delphi怎样实现?

解决方案 »

  1.   

    WebBrowser1.ExecWB(OLECMDID_SAVEAS,
                    OLECMDEXECOPT_DODEFAULT, EmptyParam,EmptyParam);
      

  2.   

    COPY一段话给你吧,希望能有用。
      如同程序里每个窗体上有一个“缺省”按钮一样,每个Web页面也有一个“缺省”按钮——即属性为“Submit”的按钮,当用户按下回车键时就相当于鼠标单击了“Submit”。但是TWebBrowser是不相应回车键的,并且,即使把包含TWebBrowser的窗体的KeyPreview设为True,在窗体的KeyPress事件等里面还是不能截获用户向TWebBrowser发出的按钮消息。
      解决的方法是用ApplicatinEvents构件或者自己编写TApplication对象的OnMessage事件,在其中判断消息类型,对键盘消息做出响应。至于点击“提交”按钮,可以通过分析网页源代码的方法来实现,不过我找到了更为简单快捷的方法,有两种,第一种是我自己想出来的,另一种是别人写的代码,这里都提供给大家,以做参考。  A、用SendKeys函数向WebBrowser发送回车键
        在Delphi 5光盘上的Info\Extras\SendKeys目录下有一个SndKey32.pas文件,其中包含了两个函数SendKeys和AppActivate,我们可以用SendKeys函数来向WebBrowser发送回车键,我现在用的就是这个方法,使用很简单,在WebBrowser获得焦点的情况下(不要求WebBrowser所包含的文档获得焦点),用一条语句即可:   Sendkeys('~',true);// press RETURN key   SendKeys函数的详细参数说明等,均包含在SndKey32.pas文件中。  B、在OnMessage事件中将接受到的键盘消息传递给WebBrowser   procedure TForm1.ApplicationEvents1Message(var Msg: TMsg; var Handled: Boolean); 
       { fixes the malfunction of some keys within webbrowser control }
       const
        StdKeys = [VK_TAB, VK_RETURN]; { standard keys }
        ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { extended keys }
        fExtended = $01000000; { extended key flag }
       begin
        Handled := False;
        with Msg do
        if ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and
         ((wParam in StdKeys) or 
         {$IFDEF VER120} (GetKeyState(VK_CONTROL) < 0) or {$ENDIF}
         (wParam in ExtKeys) and 
         ((lParam and fExtended) = fExtended)) then
        try
         if IsChild(Handle, hWnd) then { handles all browser related messages }
         begin
          with {$IFDEF VER120}Application_{$ELSE}Application{$ENDIF} as
            IOleInPlaceActiveObject do
           Handled := TranslateAccelerator(Msg) = S_OK;
           if not Handled then
           begin
            Handled := True;
            TranslateMessage(Msg);
            DispatchMessage(Msg);
           end;
           end;
        except
        end;
       end; // MessageHandler
      

  3.   

    使用D7在窗体中加入
        IdHTTP1: TIdHTTP;
        Memo1: TMemo;
        Button1: TButton;
        Edit1: TEdit;
    控件。
    设置好IdHTTP1的代理等,在button1的事件中加入代码procedure TForm1.Button1Click(Sender: TObject);
    begin
      IdHTTP1.Connected;
      Memo1.Lines.Text:= IdHTTP1.Get(Edit1.Text);
    end;
      

  4.   

    其实MEMO控件也可以直接做到,你可以试试用记事本打开在文件名中输入
       http://news.163.com/special/g/guoneinews.html便打开了国内新闻的源码。
    用MEMO.Lines.LoadFormFile("http://news.163.com/special/g/guoneinews.html")一样可以的。
      

  5.   

    上面说的是html
    如果我asp,jsp。你怎么保存源代码?