如何高效取得网页源码

时间:2010-01-26 12:53:16  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ScktComp, StdCtrls;typeTForm1 = class(TForm)ClientSocket: TClientSocket;btnLink: TButton;btnSend: TButton;Memo: TMemo;Edit: TEdit;Button1: TButton;procedure btnLinkClick(Sender: TObject);procedure btnSendClick(Sender: TObj...
  正文:

代码如下:


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;

type
TForm1 = class(TForm)
ClientSocket: TClientSocket;
btnLink: TButton;
btnSend: TButton;
Memo: TMemo;
Edit: TEdit;
Button1: TButton;
procedure btnLinkClick(Sender: TObject);
procedure btnSendClick(Sender: TObject);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
Var
f:File;

procedure TForm1.btnLinkClick(Sender: TObject);
begin
  AssignFile(f,‘out.txt‘);
  Rewrite(F,1);
  Memo.Lines.Clear;
  ClientSocket.Open;
end;

procedure TForm1.btnSendClick(Sender: TObject);
begin
  ClientSocket.Socket.SendText(‘GET /‘+Edit.Text+#$0A);
end;

procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
Var
s:String;
begin
  If Socket.Connected Then
  Begin
    s:=Socket.ReceiveText;
    Memo.Lines.Add(s);
    BlockWrite(F,s[1],Length(s));
    End;
  end;
  
  procedure TForm1.ClientSocketConnect(Sender: TObject;
  Socket: TCustomWinSocket);
  begin
    Memo.Lines.Add(‘AAAAAConn‘);
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    ClientSocket.Close;
    CloseFile(f);
  end;
  
end.


其实就是按照http协议来的...

"如何高效取得网页源码"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12413.html


关键字:

关于《如何高效取得网页源码》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td