我无法从HTML预标记中获取单个值。这是html
<html>
<head>
<style type="text/css"></style>
</head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">123456789</pre>
</body>
</html>
我尝试过使用一些例子,但似乎无法获得我需要的价值。我一直在使用vb示例。
尝试以下操作,但收到空异常错误
Dim doc As New HtmlDocument()
Dim website As New HtmlWeb()
website.Load("http://webURL.com")
doc.LoadHtml(website.ToString)
For Each pre As HtmlNode In doc.DocumentNode.SelectNodes("//pre")
MsgBox(pre.InnerText)
Next
答案 0 :(得分:1)
您应该向我们展示至少您尝试过的内容以及您需要的价值。
我猜你想要&#34; 123456789&#34;来自(未指定)网址的页面:
Imports System.Net
Imports HtmlAgilityPack
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim srcUri = "http://127.0.0.1/index.html"
Dim wc As New WebClient
'TODO: put in error handling for the download
Dim pageText = wc.DownloadString(srcUri)
Dim doc As New HtmlDocument()
doc.LoadHtml(pageText)
For Each pre As HtmlNode In doc.DocumentNode.SelectNodes("//pre")
MsgBox(pre.InnerText)
Next
End Sub
End Class
修改:上面编码的代码是从网址加载而不是使用字符串。