Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Source Code from Webview (VB for Metro)

I'm Making a Windows Phone's app that I can, From a webview called "DebWeb", get the ClassRoom of a specific class. The DebWeb load the site where is all the classRooms, but I want to make that my App search just my class.

Before I made an app with almost the same objetive (search the Name of a App from the Source Code), but it was made from VB for PC, now I'm working on VB for Metro (or for App Store) and I can't use the same code.

For example, On VB for PC I can use:

Dim EHTML = DebWeb.Document.All.Item(1)
Dim sourceString As String = EHTML.InnerHtml
'Use Regex Match to search from SourceString"

But on VB for Metro it's shows me the " 'Document' is not a member of 'Windows.UI.XAML.Controls.WebView' " error, so I can't get the Source Code from the page and I can't look for the ClassRoom.

I Looked on the MSDN page about Webview but the most close thing that I can do is to get the "DocumentTittle", but not the content.

This is my code, everything "works" except the "Source" variable:

    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)

Edited with my Entire code:

Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

    Dim URL As String = "http://agenda.uai.cl/clasesRotativa.aspx?codUbicacion=142o143o144&bannerWidth=350&tamanoLetra=14px&numFilas=35&frecuenciaSegundosHorarios=99&diasAdelanto=0&mostrarFinalizados=false&codUso=53o55o57o60o61o62o63o66o67o69o70"
    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
like image 708
JuanP. Zuniga Avatar asked Jul 23 '26 11:07

JuanP. Zuniga


1 Answers

Something like this?

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

More Info here

like image 107
TheCoolFrood Avatar answered Jul 25 '26 05:07

TheCoolFrood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!