Solved

get the source code of current web page in browser

Posted on 2004-08-07
7
278 Views
Last Modified: 2010-04-04
Hi,

Is there a way to read the source code of current web page in browser(ie, netscape, if more will be better)

Regards
0
Comment
Question by:wangzheng
7 Comments
 
LVL 10

Expert Comment

by:kiranghag
ID: 11745251
not sure in delphi, but if you can make a http connection through network programming, you can get the source.
by this smethod, u cannot get the source for the pages which do not need to establish a session (e.g webmail)
but can get pages which can be accessed by the url directly.
0
 
LVL 2

Expert Comment

by:Bobcsi
ID: 11745949
You get the URL in IExplorer with this code:

uses
  DDEMan;

// TForm type declaration...

procedure TForm1.Button1Click(Sender: TObject);
var
  DDE: TDDEClientConv;
begin
  DDE := TDDEClientConv.Create(self);
  if DDE.SetLink('IExplore', 'WWW_GetWindowInfo') then
    Memo1.Lines.Add(DDE.RequestData('0xFFFFFFFF,sURL,sTitle'));
  DDE.Free;
end;


Then, you download this page with indy HTTP Client components.


var s1:ansistring;
begin
  s1:=idhttp1.Get('http://www.url.com');
end;
0
 
LVL 4

Accepted Solution

by:
ErikPhilips earned 100 total points
ID: 11746170
If you want to write an app that reads the source from all IEs loaded:
(I believe this works properly, i have a lot of extra code to make sure all the sites are valid (ie not Images or Text files)).

procedure SomProcedure;
var
  ShellWin: IShellWindows;
  i: Integer;
  iWeb: IWebbrowser2;
  iDoc: IHTMLDocument2;
  tmpHwnd: tHwnd;
begin

  ShellWin := CoShellWindows.Create;
  for i := 0 to ShellWin.Count - 1 do
  begin
    iWeb := ShellWin.Item(i) as IWebbrowser2;
    try
      if (pos('http://', iWeb.Get_LocationURL) = 1) then  // could add https://
      begin
        try
          iDoc :=(iWeb.document as IHTMLDocument2);
          if (iDoc.protocol = 'HyperText Transfer Protocol') then
           begin
              htmlTitle := idoc.title;
              htmlURL := idoc.url;
              htmlSource := iDoc.body.innerHTML; //  This is the source as the browser recieved it, does not contain changes from scripts
           end;
        except
        end;
      end;
    except
    end;
  end;
  ShellWin.Free;
end;





0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11750527
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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