Solved

Getting Tag's innerHTML

Posted on 2006-11-01
10
1,499 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now