Solved

How to parse a text from html code in delphi?

Posted on 2011-03-03
10
686 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now