save all TWebbrowser Frame Sources? uses ActiveX; function TForm1.GetFrame(FrameNo: Integer): IWebbrowser2; var OleContainer: IOleContainer; enum: IEnumUnknown; unk: IUnknown; Fetched: PLongint; begin while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages; if Assigned(Webbrowser1.document) then begin Fetched := nil; OleContainer := Webbrowser1.Document as IOleContainer; OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, Enum); Enum.Skip(FrameNo); Enum.Next(1, Unk, Fetched); Result := Unk as IWebbrowser2; end else Result := nil; end; // Load sample page // Testseite laden procedure TForm1.Button1Click(Sender: TObject); begin Webbrowser1.Navigate('http://www.warebizprogramming.com/tutorials/html/framesEx1.htm'); end; // Save all frames in single files // Alle Frameseiten in einzelne Dateien speichern procedure TForm1.Button2Click(Sender: TObject); var IpStream: IPersistStreamInit; AStream: TMemoryStream; iw: IWebbrowser2; i: Integer; sl: TStringList; begin for i := 0 to Webbrowser1.OleObject.Document.frames.Length - 1 do begin iw := GetFrame(i); AStream := TMemoryStream.Create; try IpStream := iw.document as IPersistStreamInit; if Succeeded(IpStream.save(TStreamadapter.Create(AStream), True)) then begin AStream.Seek(0, 0); sl := TStringList.Create; sl.LoadFromStream(AStream); sl.SaveToFile('c:\frame' + IntToStr(i) + '.txt'); // memo1.Lines.LoadFromStream(AStream); sl.Free; end; except end; AStream.Free; end; end; end.
Webbrowser1.OleObject.Document.all.intertext
TO: gdbzh完整的代码怎么写?谢谢了!
uses MSHTML,OleCtrls, SHDocVw, StdCtrls,ActiveX; function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean; var ps: IPersistStreamInit; s: string; ss: TStringStream; sa: IStream; begin ps := WB.document as IPersistStreamInit; s := ''; ss := TStringStream.Create(s); try sa:= TStreamAdapter.Create(ss, soReference) as IStream; Result := Succeeded(ps.Save(sa, Bool(True))); if Result then ACode.Add(ss.Datastring); finally ss.Free; end; end;
上面的代码将WB中的网页内容保存到TStrings ACode中。
procedure TForm1.Button12Click(Sender: TObject); begin Webbrowser1.Navigate('http://www.yahoo.com'); while WebBrowser1.ReadyState < READYSTATE_INTERACTIVE do //頁面激活 Application.ProcessMessages; Memo1.Lines.Add(WebBrowser1.OleObject.Document.body.innerHtml); Memo1.Lines.SaveToFile( ExtractFilePath (Application.ExeName) + 'temp1.txt'); Edit1.Text := WebBrowser1.OleObject.Document.title; end;
ActiveX; function TForm1.GetFrame(FrameNo: Integer): IWebbrowser2;
var
OleContainer: IOleContainer;
enum: IEnumUnknown;
unk: IUnknown;
Fetched: PLongint;
begin
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages;
if Assigned(Webbrowser1.document) then
begin
Fetched := nil;
OleContainer := Webbrowser1.Document as IOleContainer;
OleContainer.EnumObjects(OLECONTF_EMBEDDINGS, Enum);
Enum.Skip(FrameNo);
Enum.Next(1, Unk, Fetched);
Result := Unk as IWebbrowser2;
end
else
Result := nil;
end; // Load sample page
// Testseite laden
procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate('http://www.warebizprogramming.com/tutorials/html/framesEx1.htm');
end; // Save all frames in single files
// Alle Frameseiten in einzelne Dateien speichern
procedure TForm1.Button2Click(Sender: TObject);
var
IpStream: IPersistStreamInit;
AStream: TMemoryStream;
iw: IWebbrowser2;
i: Integer;
sl: TStringList;
begin
for i := 0 to Webbrowser1.OleObject.Document.frames.Length - 1 do
begin
iw := GetFrame(i);
AStream := TMemoryStream.Create;
try
IpStream := iw.document as IPersistStreamInit;
if Succeeded(IpStream.save(TStreamadapter.Create(AStream), True)) then
begin
AStream.Seek(0, 0);
sl := TStringList.Create;
sl.LoadFromStream(AStream);
sl.SaveToFile('c:\frame' + IntToStr(i) + '.txt');
// memo1.Lines.LoadFromStream(AStream);
sl.Free;
end;
except
end;
AStream.Free;
end;
end; end.
gdbzh完整的代码怎么写?谢谢了!
MSHTML,OleCtrls, SHDocVw, StdCtrls,ActiveX;
function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean;
var
ps: IPersistStreamInit;
s: string;
ss: TStringStream;
sa: IStream;
begin
ps := WB.document as IPersistStreamInit;
s := '';
ss := TStringStream.Create(s);
try
sa:= TStreamAdapter.Create(ss, soReference) as IStream;
Result := Succeeded(ps.Save(sa, Bool(True)));
if Result then ACode.Add(ss.Datastring);
finally
ss.Free;
end;
end;
begin
Webbrowser1.Navigate('http://www.yahoo.com'); while WebBrowser1.ReadyState < READYSTATE_INTERACTIVE do //頁面激活
Application.ProcessMessages; Memo1.Lines.Add(WebBrowser1.OleObject.Document.body.innerHtml);
Memo1.Lines.SaveToFile( ExtractFilePath (Application.ExeName) + 'temp1.txt');
Edit1.Text := WebBrowser1.OleObject.Document.title;
end;
Memo1.Lines.Add(WebBrowser1.OleObject.Document.all.outerHtml);{取得html源码}
Memo1.Lines.Add(WebBrowser1.OleObject.Document.all.outertext);{取得html的text文本}
Memo1.Lines.Add(WebBrowser1.OleObject.Document.all.innerHtml);{取得内html的text文本}