![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как получить код страницы загуженной с помомщью TWebBrowser [D7, Win95/98, WinME, Win2k, WinXP]
Yuron © (2006-07-08 06:29:00)Скажите плииззз, как использовать компонент TWebBrowser через прокси сервер и получить HTML-код загруженной страницы. Спасибо
Maverik (2006-07-11 14:02:00) [1]А ни у кого ошибка типа 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;
}
easy (2006-07-11 13:09:00) [2]http://www.delphimaster.ru/cgi-bin/forum.pl?id=1152285976&n=0
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.