Вниз
Скачать: CL | DM;

Как получить код страницы загуженной с помомщью TWebBrowser   Найти похожие ветки 

← →
Yuron   (2006-07-08 06:29) [0]

Скажите плииззз, как использовать компонент TWebBrowser через прокси сервер и получить HTML-код загруженной страницы. Спасибо


← →
easy ©   (2006-07-11 13:09) [1]

http://delphimaster.net/view/1-1152285976/

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, OleCtrls, activex, mshtml, SHDocVw;

type
 TForm1 = class(TForm)
   WebBrowser1: TWebBrowser;
   Memo1: TMemo;
   procedure FormCreate(Sender: TObject);
   procedure WebBrowser1DocumentComplete(Sender: TObject;
     const pDisp: IDispatch; var URL: OleVariant);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

function WB_GetHTMLCode(WebBrowser: iwebbrowser2; ACode: TStrings): Boolean;
var
 ps: IPersistStreamInit;
 ss: TStringStream;
 sa: IStream;
 s: string;
begin
 ps := WebBrowser.Document as IPersistStreamInit;
 s := "";
 ss := TStringStream.Create(s);
 try
   sa := TStreamAdapter.Create(ss, soReference) as IStream;
   Result := Succeeded(ps.Save(sa, True));
   if Result then ACode.Add(ss.Datastring);
 finally
   ss.Free;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 WebBrowser1.Navigate("ya.ru");
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
 const pDisp: IDispatch; var URL: OleVariant);
begin
 memo1.Clear;
 WB_GetHTMLCode(WebBrowser1.DefaultInterface,memo1.Lines);
end;

end.


← →
Maverik   (2006-07-11 14:02) [2]

А ни у кого ошибка типа Access violation на строчке
Result := Succeeded(ps.Save(sa, True)); не вылетает?
.......................................
можно еще так:

var
 Document: IHTMLDocument2;
begin
Document := WB.Document as IHtmlDocument2;
if Document < >  nil then
  Memo1.Text := (Document.all.Item(NULL, 0) as IHTMLElement).OuterHTML;

{
или
  Memo1.Text := (Document.all.Item(NULL, 0) as IHTMLElement).OuterText;
}



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.032 c
1-1161325809
MsGuns
2006-10-20 10:30
2006.12.03
Как заставить Excel завершить печать не текущей странице


2-1163504867
MishaLukash
2006-11-14 14:47
2006.12.03
TCustomDBGrid? видел только в хелпе


2-1163530310
Vasiliy
2006-11-14 21:51
2006.12.03
Перекрыл GetClientRect, отрисовывается не весь компонент


15-1163508842
Андрей Сенченко
2006-11-14 15:54
2006.12.03
DOC. Память для EXEC


15-1163708207
Yeg
2006-11-16 23:16
2006.12.03
PowerPoint и звуковой файл




   Наверх