Solved

Internet explorer source

Posted on 2001-06-29
11
203 Views
Last Modified: 2010-04-04
Hi,
I need code to save the source from the currently active internet explorer page, to a file.

thank you
// peymanz
0
Comment
Question by:peymanz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 6237960
Here's an example of something I did recently....

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(Sender: TObject; var Key: Char);
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: TObject);
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.ClientWidth-24;
     Memo1.Width:=Form1.ClientWidth-24;
     Memo1.Height:=Form1.ClientHeight-80;
end;

procedure TForm1.NMHTTP1Connect(Sender: TObject);
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

0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6237964
This bit is not too comprehensive because it only works with IE...

function Get_URL: String;
var
     Client: TDDEClientConv;
begin
     Result:='';
     Client:=TDDEClientConv.Create(nil);
     With Client do begin
          SetLink('IExplore', 'WWW_GetWindowInfo');
          Result:=StrPas(RequestData('0xFFFFFFFF'));
          CloseLink;
     end;
     Client.Free;
end;

but there was a more comprehensive version done on EE recently.....worth searching for.

John.
0
 
LVL 2

Author Comment

by:peymanz
ID: 6238350
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:Jaymol
ID: 6238360
If you alter the above code to suit your needs, it will do what you asked for.

John.
0
 
LVL 2

Author Comment

by:peymanz
ID: 6238416
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
0
 
LVL 2

Author Comment

by:peymanz
ID: 6238417
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
0
 
LVL 1

Expert Comment

by:MoonCalf
ID: 6238427
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.
0
 
LVL 2

Author Comment

by:peymanz
ID: 6238460
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
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6238466
Okay.
0
 
LVL 2

Accepted Solution

by:
SChertkov earned 160 total points
ID: 6238592
You must use IPersistFile in DocumentComplete event

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  pf: IPersistFile;
begin
  if pDisp = WebBrowser1.ControlInterface then
    begin
      if Succeeded(WebBrowser1.Document.QueryInterface(IPersistFile, pf)) then
        OleCheck(pf.Save('1.htm', True));
    end;
end;
0
 
LVL 2

Author Comment

by:peymanz
ID: 6765834
Sorry, I had forgot to give the points.

// regards
peymanz
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question