0

Like the title says I have the html source that contains the code below. I am trying to grab the number 25 which can change so I think I would use the wildcard .* but I am not sure how to grab it because I the number is on its own line. I usually used one line of html then used the split method and split the double quotes then getting the value. I know how to do html webrequest and webresponse, so I have no problem getting the source. Any help with the regex expression would be appreciated.

<td class="number">25</td>

Edit: This is what I used to get the source.

Dim strURL As String = "mysite"
Dim strOutput As String = ""
Dim wrResponse As WebResponse
Dim wrRequest As WebRequest = HttpWebRequest.Create(strURL)
wrResponse = wrRequest.GetResponse()

Using sr As New StreamReader(wrResponse.GetResponseStream())
    strOutput = sr.ReadToEnd()
    'Close and clean up the StreamReader
    sr.Close()
End Using
2
  • You might want to read this stackoverflow.com/questions/1732348/… Commented Aug 12, 2014 at 3:03
  • You may want to check out CsQuery and use that instead. Commented Aug 14, 2014 at 21:13

1 Answer 1

1

Instead of a Regex, it is possible to use a string search to pull out the text, e.g.:

Sub Main()
    Dim html = "<td class=""number"">" + vbCrLf + "25" + vbCrLf + "</td>"
    Dim startText = "<td class=""number"">"
    Dim startIndex = html.IndexOf(startText) + startText.Length
    Dim endText = "</td>"
    Dim endIndex = html.IndexOf(endText, startIndex)        
    Dim text = html.Substring(startIndex, endIndex - startIndex)
    text = text.Trim({CChar(vbLf), CChar(vbCr), " "c})
    Console.WriteLine(text)
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

I added more code at the top which is how I get the source of the page. Using your code and mine, how would I have it search through strOutput (string for page source).
simply use strOutput instead of the example html string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.