Solved

Getting Tag's innerHTML

Posted on 2006-11-01
10
1,504 Views
Last Modified: 2012-06-27
Im trying to extract information in tags on a webpage eg:

Dim str as string = "<td>TEXT</td><td>TEST</td>"


I want somthing to return "TITLE" & "TEST" seperately nothing more prefribly using regular expressions.

Thanks in advance. Bolter99. :)

0
Comment
Question by:Bolter99
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17853018
      Here's one "simple-minded" approach, that works for most files:

           #!/usr/bin/perl -p0777
           s/<(?:[^>'"]*|(['"]).*?\1)*>//gs

       If you want a more complete solution, see the 3-stage striphtml program
       in http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz .

       Here are some tricky cases that you should think about when picking a
       solution:

           <IMG SRC = "foo.gif" ALT = "A > B">

           <IMG SRC = "foo.gif"
                ALT = "A > B">

           <!-- <A comment> -->

           <script>if (a<b && a>c)</script>

           <# Just data #>

           <![INCLUDE CDATA [ >>>>>>>>>>>> ]]>

       If HTML comments include other tags, those solutions would also break
       on text like this:

           <!-- This section commented out.
               <B>You can't see me!</B>
           -->
0
 
LVL 1

Author Comment

by:Bolter99
ID: 17853275
Sorry i thought it was the VB.Net section. I want a VB.Net solution.

Sorry & thanks for your time none the less.

PS: I meant want somthing to return "TEXT" & "TEST" not title. (the innerHTML of the <td> tags).
0
 
LVL 3

Expert Comment

by:jay_gadhavi
ID: 17855811
use innerText
Dim text1 As String = TDcontainsText.InnerText.ToString
*****TDcontainsText is the id of the td in html and this td must be runat at server side.
0
 
LVL 1

Author Comment

by:Bolter99
ID: 17857990
But strings dont have that option. PLUS, they wont have ID's. I want a way to do it through Regular Expressions.

Example:

CODE:
<table>
<tr>
 <td>Value 1</td><td>Value2</td><td>Value3</td>
</tr>
</table>

I want to isolate the cell values and nothing more.

So i can do somthing like:

Matches.Item(0).Group(1).Value to output "Value 1"
Matches.Item(0).Group(2).Value to output "Value 2"
Matches.Item(0).Group(3).Value to output "Value 3"

Understand?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Bolter99
ID: 17857996
NOTE: I use Visual Basic .Net (Vistual Studio 2005 8.0)
0
 
LVL 3

Expert Comment

by:jay_gadhavi
ID: 17865543
Use This Example :  You must defined a table as runat server

<table runat='server' id="TableTwo">
    <tr>
    <td>jay</td><td>gadhavi</td>
    </tr>
    <tr>
    <td>mukesh</td><td>prajapati</td>
    </tr>
</table>

now, In code behind use the following code

Dim text1 As String = TableTwo.Rows.Count.ToString
Dim text2 as string =TableTwo.Rows(0).Cells(0).InnerText.ToString
Dim text3 as string=TableTwo.Rows(0).Cells(1).InnerText.ToString
Dim text4 as string=TableTwo.Rows(1).Cells(0).InnerText.ToString
Dim text5 as string=TableTwo.Rows(1).Cells(1).InnerText.ToString

Debug the program check the result



         


0
 
LVL 1

Author Comment

by:Bolter99
ID: 17867031
Im not using ASP.NET

Im using:

Visual Basic .NET
0
 
LVL 1

Author Comment

by:Bolter99
ID: 17867606
Ive figured it out now, thanks for all the posts, as i myself discovered the solution i will not be awarding anypoints. Sorry. But heres my Code:


        Dim text As String = "<td>Value A</td><td>Value B</td>"
        Dim pattern As String = "<td>(.+?)</td><td>(.+?)</td>"
        Dim pat As New Regex(pattern)

        MsgBox("TD A = " & pat.Match(text, pattern).Groups(1).Value)

Output:
A message box with "TD A = Value A" would appear.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18061612
PAQed with points refunded (50)

Computer101
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

919 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

21 Experts available now in Live!

Get 1:1 Help Now