Vb.net 等待web浏览器加载第一页Visual Basic Net
我想做一个两步的源代码下载过程。所以我喜欢Vb.net 等待web浏览器加载第一页Visual Basic Net,vb.net,web,Vb.net,Web,我想做一个两步的源代码下载过程。所以我喜欢 WebBrowser1.Navigate("http://www.first-site.com") 'HERE code for downloading and saving the source code of the site into a variable 'Directly after having downloaded the source, open the second site and do the same WebBrowser1
WebBrowser1.Navigate("http://www.first-site.com")
'HERE code for downloading and saving the source code of the site into a variable
'Directly after having downloaded the source, open the second site and do the same
WebBrowser1.Navigate("http://www.first-site.com/sub-site")
'Download the Source code into one string variable
问题是,我的web浏览器将以非常快的速度直接加载两个站点,无法下载这两个站点的源代码
我尝试了所有的方法,我在谷歌上搜索“等待浏览器加载一个站点”等等,还有所有与while相关的方法,循环查看浏览器是否加载了一个站点,它会使我的程序崩溃
怎么办?您需要使用
DocumentCompleted
事件,如文档所示
在事件处理程序方法中,调用WebBrowser1.Navigate()
导航到第二个URL。检查e.Url
以查看哪个Url正在完成,这样您就不会陷入循环
从文件中:
Private Sub PrintHelpPage()
' Create a WebBrowser instance.
Dim webBrowserForPrinting As New WebBrowser()
' Add an event handler that prints the document after it loads.
AddHandler webBrowserForPrinting.DocumentCompleted, New _
WebBrowserDocumentCompletedEventHandler(AddressOf PrintDocument)
' Set the Url property to load the document.
webBrowserForPrinting.Url = New Uri("\\myshare\help.html")
End Sub
Private Sub PrintDocument(Sender As Object, e As WebBrowserDocumentCompletedEventArgs)
Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)
' Print the document now that it is fully loaded.
webBrowserForPrinting.Print()
MessageBox.Show("print")
' Dispose the WebBrowser now that the task is complete.
webBrowserForPrinting.Dispose()
End Sub
如果你只是想下载源代码,你最好用一个。我的答案解决了你的问题吗?如果是这样,请您相应地标记它。如果没有,请告诉我,我会尽力进一步帮助你。