0
好的,在我正在處理的幾個應用程序中,我一直對 Web瀏覽器控件有很多麻煩。 他們都有共同的問題。我想讓應用程序導航的網頁a讀取將頁面源代碼中的文本寫入變量。之後我還需要能夠保存文件。從頁面源拉取信息
一些源代碼:
Public Class Form4
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox1.Text = MyFolderBrowser.SelectedPath
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("You have to select a directory!")
Else
WebBrowser1.Navigate("www.realmofthemadgod.com/version.txt")
System.Threading.Thread.Sleep(3000)
Dim PageSource As String = WebBrowser1.Document.Body.InnerText
WebBrowser1.Navigate("http://www.realmofthemadgod.com/AssembleeGameClient" & PageSource & ".swf")
End If
End Sub
末級
我有一個問題的第一件事是,它從不等待網頁拉動文檔文本之前加載。我嘗試了許多不同的方法,從人們發佈的不同解決方案中解脫出來。奇怪的是,如果我第二次這樣做,似乎總能奏效。
如果單擊Button2,我想將最終生成的網頁保存爲swf到選定的目錄。
感謝所有幫助我一直在尋找這個到處
謝謝你的快速響應。我一回家就會檢查一下。我也會看看你提到的包,因爲我需要在一個rleated應用程序中解析一個html數組。 WebClient會在後臺工作,還是導致保存爲對話框? – Matt 2013-05-08 01:37:45
它在後臺運行。如果您不希望在請求期間阻止用戶界面,還有一個異步版本。 – 2013-05-08 04:36:43
這工作完美,你真棒 – Matt 2013-05-08 06:02:05