如何从本地HTML文件中获取部分文本并将其用作变量? [英] How to grab a part of text from a local HTML file and use it as variable?

查看:292
本文介绍了如何从本地HTML文件中获取部分文本并将其用作变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB制作一个小型的home应用程序。正如标题所说,我想从本地html文件中获取部分文本并将其用作变量,或者将其放在文本框中。



我尝试了什么:



我尝试过这样的事情......

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...

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

结果是加载整个此文本框中的HTML代码。我该怎么做才能获取html文件代码的特定部分?假设我想从这个范围中抓取文字...

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...

<span id="text">Text</a>

推荐答案

使用类似 Agility Pack [ ^ ]解析html并提取你想要的位。
Use something like the Agility Pack[^] to parse the html and extract the bits you want.


这篇关于如何从本地HTML文件中获取部分文本并将其用作变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆