I'm pretty new to VB.NET and I'm still learning, please help me understand this endeavor or mine.
I have written code to download a webpage HTML source code into a .txt file, once downloaded, the code I posted here adds all lines as strings into a list and is supposed to find an anchor point as a position reference and then jump down the list to the real keyword.
I have an anchor point in this list that is a constant that I will always "know of" but I need to jump down 3 lines below this anchor point to the real keyword I'm looking for that is always "unknown to me" since it's a variable.
My anchor point is the keyword Hair Color which both the words and the line they're on are unique in the entire source code.
My target keyword is the variable Brown (in this case), that I can't target directly because neither it nor the line it's on are unique and will change from query to query.
The HTML table source code like the one below is always structured the same but some pages may vary in layout depending on the keywords applicable on the webpage. The code structure below however is always a constant, you can always count on all the webpages that the keyword Hair Color is always the 3 line into the table row and its variable is always 3 lines below that. So even though the answer I'm looking for is always 3 lines below my anchor point, my anchor point will not always be on the same line of code in the source code.
HTML code in the .txt file:
<tr> <td class="paramname"> <b>Hair Color</b> </td> <td class="paramvalue"> Brown </td> </tr>
I'm having a great deal of trouble trying to figure out just how I'm to "jump down" 3 lines of strings in my list to my target keyword.
My code thus far:
Public Sub TestSub()
' Creates sr as StreamReader for the .txt file with the HTML code
Dim sr As System.IO.StreamReader = New System.IO.StreamReader("C:\TEST\downloaded.txt")
' Creates the list
Dim lines As New List(Of String)
' Adds the lines of HTML code to the list
While Not sr.EndOfStream
lines.Add(sr.ReadLine)
End While
' Loops through the list in search of my anchor point Hair Color
Dim FoundIt As String = ""
Dim line As String = ""
For Each line In lines
If line.Contains("Hair Color") Then
' Now I've found the anchor point and if I output the following:
FoundIt = line
msgbox(FoundIt)
' Then it will correctly print out the entire Hair Color html line of code.
' This is the point where I need to jump down 3 lines to Brown and target
' what ever is on that line.
End If
Next
Since I'm pretty new to this I may not be using the code correctly, through my attempts I don't know how to do that jump.
Can someone please help me understand how to "skip" or "jump" down lines in my list by predefinition like:
- "ok, I found my anchor point, now I'm supposed to jump down 3 lines and pass what ever I find there to a string!"
- "ok, I found my anchor point, now I'm supposed to go to the second instance of the keyword Brown from here that I find and pass what ever I find there to a string!"
Any help is greatly appreciated!

New Topic/Question
Reply



MultiQuote







|