我正在制作一个 Windows Phone 的应用程序,我可以从名为“DebWeb”的网络视图获取特定班级的 ClassRoom。 DebWeb 加载所有教室所在的网站,但我想让我的应用程序搜索只是我的班级。
之前我制作了一个具有几乎相同目标的应用程序(从源代码中搜索应用程序的名称),但它是由 VB for PC 制作的,现在我正在开发 VB for Metro(或 App Store),我可以不要使用相同的代码。
例如,在 VB for PC 上我可以使用:
Dim EHTML = DebWeb.Document.All.Item(1)
Dim sourceString As String = EHTML.InnerHtml
'Use Regex Match to search from SourceString"
但在 VB for Metro 上,它向我显示“‘Document’不是‘Windows.UI.XAML.Controls.WebView’的成员”错误,因此我无法从页面获取源代码,也无法查看为教室。
我查看了有关 Webview 的 MSDN 页面,但我能做的最接近的事情是获取“DocumentTittle”,但不是内容。
这是我的代码,除了“Source”变量之外,所有内容都“有效”:
Dim Source = DebWeb.[Control] 'Here is where I need the Control to get the SourceCode
Dim m As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(Source.ToString, _
"DERECHO CONSTITUCIONAL", _
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
用我的整个代码进行编辑:
Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim URL As String = "http://goo.gl/uqohKw"
Me.DebWeb.Navigate(New Uri(URL))
End Sub
Private Sub DebWeb_LoadCompleted(ByVal sender As Object, ByVal e As WebViewNavigationCompletedEventArgs)
LListo.Text = "Listo!"
Dim html As String = DebWeb.InvokeScriptAsync("eval", New String() {"document.documentElement.outerHTML;"}).ToString
Dim Source = html
Dim m As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(Source.ToString, _
"LECTURA CRÍTICA", _
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
If (m.Success) Then
Dim key As String = m.Groups(1).Value
End If
End Sub