Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting Tag's innerHTML

Posted on 2006-11-01
10
Medium Priority
?
1,545 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
[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
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
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!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

604 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