Click here to Skip to main content
15,918,617 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am making a small "home" application using VB. As the title says, I want to grab a part of text from a local html file and use it as variable, or put it in a textbox.

What I have tried:

I have tried something like this...
VB
Private Sub Open_Button_Click(sender As Object, e As EventArgs) Handles Open_Button.Click
    Dim openFileDialog As New OpenFileDialog()
    openFileDialog.CheckFileExists = True
    openFileDialog.CheckPathExists = True
    openFileDialog.FileName = ""
    openFileDialog.Filter = "All|*.*"
    openFileDialog.Multiselect = False
    openFileDialog.Title = "Open"

    If openFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
        Dim fileReader As String = My.Computer.FileSystem.ReadAllText(openFileDialog1.FileName)
            TextBox.Text = fileReader
    End If
End Sub
The result is to load the whole html code inside this textbox. What should I do so to grab a specific part of html files's code? Let's say I want to grab the word text from this span...
HTML
<span id="text">Text</a>
Posted
Updated 26-Mar-16 4:20am

1 solution

Use something like the Agility Pack[^] to parse the html and extract the bits you want.
 
Share this answer
 
Comments
DNA180 26-Mar-16 10:33am    
I am looking for an other way...
F-ES Sitecore 26-Mar-16 12:38pm    
If the html is xhtml you could try loading it into an XmlDocument and process it like it's xml, failing that you have to do your own parsing using regex expressions to find the text you want, or use basic string functions like IndexOf and Substring to find\extract the text you want.
Sergey Alexandrovich Kryukov 26-Mar-16 15:22pm    
Which way, exactly? You need to explain what you really want to achieve, instead of talking puzzles. Which way, why?
—SA
Sergey Alexandrovich Kryukov 26-Mar-16 15:21pm    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900