Solved

Getting Tag's innerHTML

Posted on 2006-11-01
10
1,513 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

860 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