?
Solved

Getting Tag's innerHTML

Posted on 2006-11-01
10
Medium Priority
?
1,535 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
Introduction to Processes

777 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