Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.12.03;
Скачать: 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 вся ветка

Текущий архив: 2006.12.03;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.062 c
15-1163385443
kidm
2006-11-13 05:37
2006.12.03
Нуж помощь при оброшение к файлу


2-1163685869
Новый_Юзер
2006-11-16 17:04
2006.12.03
Drag n Drop в TreeView


15-1163658844
Andy BitOff
2006-11-16 09:34
2006.12.03
Физики объясните.


6-1152629930
begginer
2006-07-11 18:58
2006.12.03
Помогите разобраться с приемом UDP пакетов


4-1153531038
Батя
2006-07-22 05:17
2006.12.03
Определиние координат