Главная страница
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.059 c
15-1163148108
click
2006-11-10 11:41
2006.12.03
Куча будильников (напоминаний)


15-1163143100
Jeer
2006-11-10 10:18
2006.12.03
Вирус


2-1163623690
framez
2006-11-15 23:48
2006.12.03
вопрос по БД: IB6.5 + BDE


15-1163193656
ArtemESC
2006-11-11 00:20
2006.12.03
Как сделать поддержку субтитров?


2-1163695212
kat_nik
2006-11-16 19:40
2006.12.03
Проверка заполненности ячеек компонента TStringGrid