从Webview获取源代码(VB for Metro)

时间:2015-04-15 15:18:47

标签: vb.net windows-phone-8 windows-8 webview

我正在创建一个Windows Phone的应用程序,通过名为" DebWeb"的Web视图,获取特定类的ClassRoom。 DebWeb加载了所有classRooms的网站,但我想让我的App搜索只是我的课程。

在我创建具有几乎相同目标的应用程序之前(从源代码中搜索应用程序的名称),但它是从VB for PC制作的,现在我正在使用VB for Metro(或用于App)商店),我不能使用相同的代码。

例如,On 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上,它向我展示了" '文件'不是Windows.UI.XAML.Controls.WebView'的成员。 "错误,所以我无法从页面获取源代码,我无法查找ClassRoom。

我在MSDN页面上查看了Webview,但我能做的最接近的事情是获取#34; 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

1 个答案:

答案 0 :(得分:1)

这样的东西?

Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    Try
        Dim html As String = Await myWebView.InvokeScriptAsync("eval", New String() {"document.documentElement.outerHTML;"})
    Catch ex As Exception
    End Try
End Sub

更多信息here

相关问题