|
-
Sep 2nd, 2010, 05:09 PM
#1
Thread Starter
Member
Multiple "TD" tagNames
Here is my code so far:
Code:
Dim htmlDoc As HtmlDocument = Me.WebBrowser1.Document
Dim visibleHtmlElements As HtmlElementCollection = htmlDoc.GetElementsByTagName("TD")
For Each str As HtmlElement In visibleHtmlElements
If Not str.InnerText Is Nothing Then
Dim text As String = str.InnerText
If text.Contains("testWord") Then
MsgBox("found")
Else
MsgBox("not found")
End If
End If
Next
There are multiple "TD" tagnames in the webpage im working with. My code looks at all of them and checks if they contain "testWord".
What I need is some way of saying:
If ANY text.Contains("testWord") Then
MsgBox("found")
Else
MsgBox("not found")
Or
If THE 8th text.Contains("testWord") Then
MsgBox("found")
Else
MsgBox("not found")
Currently im getting 20 msgBox's telling me "found" and "not found". I just want one.
-
Sep 2nd, 2010, 05:50 PM
#2
Re: Multiple "TD" tagNames
Then exit the loop as soon as you fine the first one.
Code:
Dim htmlDoc As HtmlDocument = Me.WebBrowser1.Document
Dim visibleHtmlElements As HtmlElementCollection = htmlDoc.GetElementsByTagName("TD")
For Each str As HtmlElement In visibleHtmlElements
If Not str.InnerText Is Nothing Then
Dim text As String = str.InnerText
If text.Contains("testWord") Then
MsgBox("found")
Exit For
Else
MsgBox("not found")
Exit For
End If
End If
Next
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Sep 2nd, 2010, 05:54 PM
#3
Hyperactive Member
Re: Multiple "TD" tagNames
If you're really finding 20 of them, are they all returning the same? You mention any or the 8th innertext. Will the first one found suffice, if so look above, otherwise, just keep a count for each one found, then when the count is 8, after it finds that msgbox you can exit the for loop.
-
Sep 2nd, 2010, 06:01 PM
#4
Fanatic Member
Re: Multiple "TD" tagNames
Since you're in a VB.NET forum, I will also suggest that you use MessageBox.Show() instead of MsgBox().
Strange how many people still even know of MsgBox().
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|