?
Solved

How to parse a text from html code in delphi?

Posted on 2011-03-03
10
Medium Priority
?
695 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
[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
  • 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
Independent Software Vendors: 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
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

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…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

752 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