Link to home
Start Free TrialLog in
Avatar of doyuk
doyuk

asked on

getting Source Code

I want to get the source code of a website and put it into a textbox?

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Knighty
Knighty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Knighty
Knighty

or using the ICS component http://overbyte.delphicenter.com/ :
HttpCli1.URL := 'url';
HttpCli1.RcvdStream := TMemoryStream.Create;
HttpCli1.Get;
Memo1.Lines.LoadFromStream(HttpCli1.RcvdStream);
HttpCli1.RcvdStream.Destroy;
HttpCli1.RcvdStream := nil;
Avatar of doyuk

ASKER

Thanks. It works...
doyuk, you could also use this function to get rid of all those components:

{ uses WinInet }

function LoadFromURL(URL: String): String;
var
  hSession, hURL: hInternet;
  Buffer: array[0..1023] of Byte;
  BufferLength: DWord;
  Stream: TStringStream;
begin
  stream := TStringStream.Create('');
  Result := '';
  if (Pos('http://', LowerCase(url)) = 0) then URL := 'http://' + URL;
  hSession := InternetOpen('My_App;)', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    hURL := InternetOpenURL(hSession, PChar(URL), nil, 0, INTERNET_FLAG_RELOAD, 0);
    try
      repeat
        InternetReadFile(hURL, @Buffer, 1024, BufferLength);
        Stream.WriteBuffer(Buffer, BufferLength);
        Application.ProcessMessages;
      until (BufferLength = 0);
      Result := Stream.DataString;
     finally
       InternetCloseHandle(hURL)
     end;
  finally
    InternetCloseHandle(hSession);
    Stream.free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text := LoadFromURL('www.experts-exchange.com');
end;

Markus
very good, ty dude.