Solved

get the source code of current web page in browser

Posted on 2004-08-07
7
280 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
[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
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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