html - 使用子字符串方法从 html 中提取文本
问题描述
我想从 html 中提取文本。我已经通过 webrequest 获得了 html 源代码。
如何提取如下示例中的文本?:
class="btn btn-success btn-lg" href="I wanto to get this link that is changing every time" rel="nofollow noopener">Click</a><
我可以使用像 startwith 和 end with 这样的子字符串方法吗?谢谢
解决方案
因此,使用 string.indexof 我找到了解决方案。我对 html 字符串中的那些 "" 有点挣扎,但这现在做了它应该做的事情。
我找到了解决方案!
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)
推荐阅读
- java - 如何检索 IoT 中心数据的属性,而不仅仅是实际有效负载
- kubernetes - 如何在 Kubernetes 中配置已经运行的集群
- google-maps - 如何在 vuetify 项目中使用本地文件获取自定义 gmap 图标
- python - 如何使用 tf.constant 或 numpy 数组初始化 tf.Variable?
- typescript - 必须初始化的类的打字稿类型
- java - 复制时显示电子中复制的内容
- python - 如何在 try/except 循环中创建条件?
- php - 登录失败 500 语法错误,命令无法识别
- c# - 识别正则表达式之间的字符串的问题
- javascript - Vimeo API 最终触发多个事件