Solved

get the source code of current web page in browser

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now