peymanz
asked on
Internet explorer source
Hi,
I need code to save the source from the currently active internet explorer page, to a file.
thank you
// peymanz
I need code to save the source from the currently active internet explorer page, to a file.
thank you
// peymanz
This bit is not too comprehensive because it only works with IE...
function Get_URL: String;
var
Client: TDDEClientConv;
begin
Result:='';
Client:=TDDEClientConv.Cre ate(nil);
With Client do begin
SetLink('IExplore', 'WWW_GetWindowInfo');
Result:=StrPas(RequestData ('0xFFFFFF FF'));
CloseLink;
end;
Client.Free;
end;
but there was a more comprehensive version done on EE recently.....worth searching for.
John.
function Get_URL: String;
var
Client: TDDEClientConv;
begin
Result:='';
Client:=TDDEClientConv.Cre
With Client do begin
SetLink('IExplore', 'WWW_GetWindowInfo');
Result:=StrPas(RequestData
CloseLink;
end;
Client.Free;
end;
but there was a more comprehensive version done on EE recently.....worth searching for.
John.
ASKER
The problem is that I want to get the source of the page. Getting the url and sending the request does not work, since the page will be refreshed. I want the equivalent to
view->source menu.
// peymanz
view->source menu.
// peymanz
If you alter the above code to suit your needs, it will do what you asked for.
John.
John.
ASKER
How if I understand right the first code gets the url from the edit box and requests the page. Which I can not do since the page has already been requested once from the browser and if It is requested once more the contents will change.
And the second code returns the current url of IE. It is the same problem there I can not send a new requests to the server.
Note that the page has already been requested once (from IE) and I want to get the source which is stored locally.
// peymanz
And the second code returns the current url of IE. It is the same problem there I can not send a new requests to the server.
Note that the page has already been requested once (from IE) and I want to get the source which is stored locally.
// peymanz
ASKER
How if I understand right the first code gets the url from the edit box and requests the page. Which I can not do since the page has already been requested once from the browser and if It is requested once more the contents will change.
And the second code returns the current url of IE. It is the same problem there I can not send a new requests to the server.
Note that the page has already been requested once (from IE) and I want to get the source which is stored locally.
// peymanz
And the second code returns the current url of IE. It is the same problem there I can not send a new requests to the server.
Note that the page has already been requested once (from IE) and I want to get the source which is stored locally.
// peymanz
I tried Jaymol's code and it worked.
I used the second function to get the url and then first lot of code to display the source.
MoonCalf.
I used the second function to get the url and then first lot of code to display the source.
MoonCalf.
ASKER
Sorry but as you say the first lot of code gets the page from the server before it displays it. The source is already on the computer. I do not want to get it from the server again.
// peymanz
// peymanz
Okay.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, I had forgot to give the points.
// regards
peymanz
// regards
peymanz
Unit source code....
unit htmlsource01;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Psock, NMHttp, StdCtrls;
type
TForm1 = class(TForm)
txtURL: TEdit;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
NMHTTP1: TNMHTTP;
procedure txtURLKeyPress(Sender: TObject; var Key: Char);
procedure Memo1Change(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure NMHTTP1Connect(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
JustChanged : Boolean;
implementation
{$R *.DFM}
procedure TForm1.txtURLKeyPress(Send
begin
If Key=#13 then begin
NMHTTP1.Disconnect;
txtURL.Enabled:=False;
JustChanged:=True;
Key:=#0;
txtURL.SelectAll;
NMHTTP1.InputFileMode := FALSE;
NMHTTP1.OutputFileMode := FALSE;
NMHTTP1.ReportLevel := Status_Basic;
NMHTTP1.Get(txtURL.Text);
Memo1.Text := NMHTTP1.Body;
end;
end;
procedure TForm1.Memo1Change(Sender:
var
TmpI : Integer;
TmpS : String;
begin
If JustChanged then begin
JustChanged:=False;
For TmpI:=1 to Length(Memo1.Text) do begin
If Memo1.Text[TmpI]=#10 then
TmpS:=TmpS+#13;
TmpS:=TmpS+Memo1.Text[TmpI
end;
Memo1.Text:=TmpS;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
txtURL.Width:=Form1.Client
Memo1.Width:=Form1.ClientW
Memo1.Height:=Form1.Client
end;
procedure TForm1.NMHTTP1Connect(Send
begin
txtURL.Enabled:=True;
end;
end.
Form description....
object Form1: TForm1
Left = 192
Top = 103
BorderStyle = bsSingle
Caption = 'HTML Source Viewer'
ClientHeight = 453
ClientWidth = 661
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 12
Top = 8
Width = 56
Height = 13
Caption = 'Enter URL :'
end
object Label2: TLabel
Left = 12
Top = 52
Width = 101
Height = 13
Caption = 'HTML Source Code :'
end
object txtURL: TEdit
Left = 12
Top = 24
Width = 637
Height = 21
TabOrder = 0
OnKeyPress = txtURLKeyPress
end
object Memo1: TMemo
Left = 12
Top = 68
Width = 637
Height = 373
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Courier New'
Font.Style = []
ParentFont = False
ScrollBars = ssBoth
TabOrder = 1
WordWrap = False
OnChange = Memo1Change
end
object NMHTTP1: TNMHTTP
Port = 0
ReportLevel = 0
OnConnect = NMHTTP1Connect
Body = 'Default.htm'
Header = 'Head.txt'
InputFileMode = False
OutputFileMode = False
ProxyPort = 0
Left = 16
Top = 72
end
end