Solved

twebrowser

Posted on 2009-05-18
9
210 Views
Last Modified: 2012-05-07
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.
0
Comment
Question by:Cheng_sam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24413365
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

0
 

Author Comment

by:Cheng_sam
ID: 24422515
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.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24423246
Then the HTML must be different. Let me look at it.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:EddieShipman
ID: 24423258
Yep, there are no TABLE tags in that HTML. What is it that you want to parse and into what.
0
 

Author Comment

by:Cheng_sam
ID: 24432664
I try to get some text from a html. the text may be a area from line 2 to line 4 . no table tag.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24433391
I need to know exactly what text you want from that page.
0
 

Author Comment

by:Cheng_sam
ID: 24443085
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
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 200 total points
ID: 24455808
There is no way to get words from just line 2 or line 10, you have to know the source code of the page you want to pars and how it is designed. HTML is NOT very pretty and most of the time not very well structured so it would even be difficult to parse it based on the elements.

My suggestion is to study the HTML source of the page(s) you want to pare and then come back and we can help you figure out EXACTLY what it is you want.
0
 

Author Comment

by:Cheng_sam
ID: 24649316
sorry for my late response because of my credit car expire.thanks.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month7 days, 14 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question