I am using VB.net and Webbrowser control(wbMain) to access website. I set the url to:
Then check the value in wbMain.Document.DomDocument.Body.innerHTML, but find the value is:
<div id="angular-content" style="height: 100%; min-height: 100%;">
<app-root>
</app-root>
</div>
<script>
localStorage.setItem('currentYear', 2016);
localStorage.setItem('noCheck', 'ok');
localStorage.removeItem('searchQuery');
localStorage.removeItem('searchParams');
localStorage.removeItem('currentUrl');
</script>
type="text/javascript">
src="styles.5f7f16a82a4f91544984.bundle.js"
type="text/javascript">
src="scripts.64dba058e16f4b72599d.bundle.js"
type="text/javascript">
src="main.3c0725bdf3863d8a267c.bundle.js" type="text/javascript">
Then I check wbMain.Document.DomDocument.Body.innerText and the its value
is:
localStorage.setItem('currentYear', 2016); localStorage.setItem('noCheck', 'ok');
localStorage.removeItem('searchQuery');
localStorage.removeItem('searchParams');
localStorage.removeItem('currentUrl');
None of them contain the actual search result. Why?
In my code, I have codes to wait until the web page is completely loaded, as follows:
wbMain.Navigate(New System.Uri(strURL))
LoadCompleted = False ' set the global flag to False to indicate the page has not been loaded completedly
Call WaitForNavigation2(wbMain)
and WaitForNavigation2 is:
' Wait for navigation to complete
Public Const conTimeOut As Integer = 3000
Public Sub WaitForNavigation2(ByRef wbMain As System.Windows.Forms.WebBrowser)
Dim iTickCount As Integer
iTickCount = GetTickCount()
Do While (Not LoadCompleted)
' Sleep 10
System.Windows.Forms.Application.DoEvents()
' Check for timeout
If (GetTickCount() - iTickCount) \ 1000 > conTimeOut Then
Exit Do
End If
Loop
End Sub
and in the DocumentCompleted event of the web browser control wbMain, I will set the global flag LoadCompleted to True to indicate it is loaded completedly:
Private Sub wbMain_DocumentCompleted(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wbMain.DocumentCompleted
LoadCompleted = True
End Sub
Thanks
Aucun commentaire:
Enregistrer un commentaire