return displayed text in embeddedwb



how do i get the text that is displayed in embeddedwb  browser?


i try this:

   document := web.document as IHTMLDocument2;
   memo1.Clear;
   memo1.lines.add(trim(document.body.innertext));  // to get text
   memo1.lines.savetofile('test2.txt')

it returns 2 blank lines

i try this:

procedure tform1.WB_SaveAs_HTML(WB : tembeddedwb; const FileName : string) ;
var
  PersistStream: IPersistStreamInit;
  Stream: IStream;
  FileStream: TFileStream;
begin
  if not Assigned(WB.Document) then
  begin
    ShowMessage('Document not loaded!') ;
    Exit;
  end;

  PersistStream := WB.Document as IPersistStreamInit;
  FileStream := TFileStream.Create(FileName, fmCreate) ;
  try
    Stream := TStreamAdapter.Create(FileStream, soReference) as IStream;
    if Failed(PersistStream.Save(Stream, True)) then ShowMessage('SaveAs HTML fail!') ;
  finally
    FileStream.Free;
  end;
end; (* WB_SaveAs_HTML *)

it returns--  SaveAS HTML fail

it is displayed on the screen - there must be a way to save it to file???
arwar49Asked:
Who is Participating?
 
arwar49Connect With a Mentor Author Commented:
all it returns is the html title tag
0
 
Mahdi78Commented:
try this

procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
Memo1.Text := WebBrowser1.OleObject.Document.documentElement.innerText;
end;
0
 
arwar49Author Commented:
i can't use that because i don't have a URL to feed it. I navigate to the home page and then have to drill down to section(s) i am looking for.  I need something that i can call after i have navigated - the url never changes from the top level.
0
 
Mahdi78Commented:
Can you explain more?
You can use my even with button click like htis

procedure TForm1.Button2Click(Sender: TObject);
begin
 Memo1.Text := WebBrowser1.OleObject.Document.documentElement.innerText;
end;
0
 
arwar49Author Commented:
it wasn't solved - i just want the question closed
0
All Courses

From novice to tech pro — start learning today.