Solved

How to parse a text from html code in delphi?

Posted on 2011-03-03
10
692 Views
Last Modified: 2012-05-11
HELLO.
Please help me!

I have html code of a website into a memo.

And the program need to search a value like pr : 500.

How can i do it?
Please help.

Here is a part of code :

<td class="td2_2">  //this is begin
8 / 10   //i need to parse this value which is different for every try
</td> //end


Help anyone please?
How can i use POS function to find value?

0
Comment
Question by:helyonprime96
  • 6
  • 4
10 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35027987
Do you want to find "pr : 500" or "8 / 10"?
0
 

Author Comment

by:helyonprime96
ID: 35028026
i need  to find 8 / 10

but this value is not 8 / 10 for every domain.
i need to make a function that find the text between <td class="td2_2"> and </td>..
Can you help me?
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35028091
Let's say you want to find that when a button is clicked then your code goes like this:
procedure TForm1.Button1Click(Sender: TObject);
var
  str:string;
begin
  str:=Memo1.Text;
  repeat
    delete(str,1,pos('<td class',str)+1);
    showmessage(trim(copy(str,pos('>',Str)+1,pos('</td>',str)-pos('>',Str)-1)));
  until pos('<td class',Str) <= 0;
end;

Open in new window

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:helyonprime96
ID: 35028235
thanks, it tested it, but it displays me very many texts and not that i need.
0
 

Author Comment

by:helyonprime96
ID: 35028247
please tell me how can i copy the numbers between

<td class="td2_2">
 and

 </td>
??
0
 

Author Comment

by:helyonprime96
ID: 35028299
ok.i have done some modifications and it is good.
it displays me only 3 values.

How can i do that this procedure excludes 2 values from search?
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35028357
If you are sure it will be in that format (i.e. <td class="td2_2"> and  </td>) then:
procedure TForm1.Button1Click(Sender: TObject);
var
  str:string;
begin
  str:=Memo1.Text;
  repeat
    delete(str,1,pos('<td class="td2_2">',str)+length('<td class="td2_2">'));
    showmessage(trim(copy(str,pos('<td class="td2_2">',Str)+1,pos('</td>',str)-pos('<td class="td2_2">',Str)-1)));
  until pos('<td class="td2_2">',Str) <= 0;
end;

Open in new window

0
 

Author Comment

by:helyonprime96
ID: 35028407
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35028904
Please ignore all my above posts, here is the correct one:
procedure TForm1.Button1Click(Sender: TObject);
var
  str:string;
begin
  str:=Memo1.Text;
  repeat
    delete(str,1,pos('<td class="td2_2">',str)+ length('<td class="td2_2">')-1);
    showmessage(trim(copy(str,1,pos('</td>',str)-1)));
  until pos('<td class="td2_2">',Str) <= 0;
end;

Open in new window

0
 

Author Closing Comment

by:helyonprime96
ID: 35029157
thanks, code works!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 69
detecting  the added row index in a datagridview 3 80
ejb entity bean example 2 17
Bot application - advice 3 38
A short article about a problem I had getting the GPS LocationListener working.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

831 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