Вниз
Скачать: 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.034 c
2-1163340455
Itonixxx
2006-11-12 17:07
2006.12.03
переос данных из ibQuery


15-1163568336
jiny
2006-11-15 08:25
2006.12.03
Знаком ли кто-нибудь с теорией создания программы дактилоскопии ?


8-1145099031
Серджинйо
2006-04-15 15:03
2006.12.03
Попиксельно нарисовать эллипс


15-1163005158
Sergey Masloff
2006-11-08 19:59
2006.12.03
Про то как все ругались на 10 тыс зарплаты по письму Думкина


2-1163327804
lsvit
2006-11-12 13:36
2006.12.03
Работа с exe файлами




   Наверх