Link to home
Start Free TrialLog in
Avatar of Cheng_sam
Cheng_sam

asked on

twebrowser

Hi experts,
I need get  text from  twebwrowser by code.for example,get all the text in twebrowser from  row 3  to row5 .How to?thanks.
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Try something like this:
procedure TForm1.ParseResults(sl: TStringList);
var
 i, j: Integer;
begin
 for i := 0 to sl.Count-1 do
 begin
   if Pos('(1)', sl.Strings[i]) > 0 then
   begin
     for j := 0 to 39 do
     begin
       Memo1.Lines.Add(sl.Strings[i+j]);
     end;
   end;
 end;
end;
 
procedure TForm1.ParseFile(var sl: TStringList);
var
i, j: integer;
ovTable: OleVariant;
s: String;
begin
ovTable := WebBrowser1.OleObject.Document.all.tags('TABLE').item(0);
for i := 0 to (ovTable.Rows.Length - 1) do
begin
  for j := 0 to (ovTable.Rows.Item(i).Cells.Length - 1) do
  begin
    s := ovTable.Rows.Item(i).Cells.Item(j).innerText;
    sl.Text := s;
  end;
end;
end;
 
procedure TForm1.FormShow(Sender: TObject);
begin
 memo1.Lines.Clear;
 Webbrowser1.navigate('http://localhost/top40.html');
end;
 
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
 const pDisp: IDispatch; var URL: OleVariant);
var
 sl: TStringList;
begin
 sl := TStringList.Create;
 try
   Parsefile(sl);
 finally
   ParseResults(sl);
   sl.Free;
 end;
end;

Open in new window

Avatar of Cheng_sam
Cheng_sam

ASKER

thanks for your comment.
I have tested the codeand change the Webbrowser1.navigate('http://localhost/top40.html') to
'http://www.martinstoeckli.ch/delphi/delphi.html#AppLink'.it  see nothing.
Then the HTML must be different. Let me look at it.
Yep, there are no TABLE tags in that HTML. What is it that you want to parse and into what.
I try to get some text from a html. the text may be a area from line 2 to line 4 . no table tag.
I need to know exactly what text you want from that page.
for axample,I visit google and search some key word.the pages show  a couple of result  .I want copy some word showed in page from line2 to line10(or others)   by code. the twebbrowser (or other method)can do this?
thanks
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry for my late response because of my credit car expire.thanks.