user14431754
user14431754

Reputation:

Extract text from html with substring methods

I wanto to extract text from html. I'm already getting html source with webrequest.

How can I extract text like the following example?:

class="btn btn-success btn-lg" href="I wanto to get this link that is changing every time" rel="nofollow noopener">Click</a><

Can I do it using substring methods like startwith and end with? Thanks

Upvotes: 0

Views: 293

Answers (1)

user14431754
user14431754

Reputation:

So, Using string.indexof I found a solution. I was strugglin a bit with those "" in html string, but this now does what it is supposed to do.

I found the solution!

 Dim allinputtext As String = RichTextBox1.Text
    Dim textafter As String = """ rel=""nofollow noopener"
    Dim textbefore As String = "class=""btn btn-success btn-lg"" href="""
    Dim startPosition As Integer = allInputText.IndexOf(textBefore)

    'If text before was not found, return Nothing
    If startPosition < 0 Then

    End If

    'Move the start position to the end of the text before, rather than the beginning.
    startPosition += textBefore.Length

    'Find the first occurrence of text after the desired number
    Dim endPosition As Integer = allInputText.IndexOf(textAfter, startPosition)

    'If text after was not found, return Nothing
    If endPosition < 0 Then

    End If

    'Get the string found at the start and end positions
    Dim textFound As String = allInputText.Substring(startPosition, endPosition - startPosition)
    TextBox4.Text = (textFound)

Upvotes: 2

Related Questions