Solved

How to parse a text from html code in delphi?

Posted on 2011-03-03
10
693 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

733 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