Link to home
Start Free TrialLog in
Avatar of helyonprime96
helyonprime96

asked on

How to parse a text from html code in delphi?

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?

Avatar of jimyX
jimyX

Do you want to find "pr : 500" or "8 / 10"?
Avatar of helyonprime96

ASKER

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?
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

thanks, it tested it, but it displays me very many texts and not that i need.
please tell me how can i copy the numbers between

<td class="td2_2">
 and

 </td>
??
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?
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

ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

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
thanks, code works!