Vb.net 从页面源中提取信息
好的,所以我一直有很多麻烦 我正在开发的几个应用程序上的Web浏览器控件。 他们都有相同的问题。我想让应用程序导航的网页a读写页面源中的文本到一个变量。我还需要能够保存文件后 一些源代码:Vb.net 从页面源中提取信息,vb.net,visual-studio-2010,visual-studio,Vb.net,Visual Studio 2010,Visual Studio,好的,所以我一直有很多麻烦 我正在开发的几个应用程序上的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 N
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
末级
我遇到的第一个问题是,它从不等待网页加载后再提取文档文本。我尝试了许多不同的方法,从人们发布的不同解决方案中找到解决方案。奇怪的是,如果我再做一次,它似乎总是起作用
如果单击按钮2,我想将最终生成的网页作为swf保存到所选目录
感谢您的帮助,我一直在到处寻找这个欢迎来到黑暗的网络抓取艺术。首先,我建议使用WebBrowser而不是WebBrowser,因为它有从网站下载数据的离散方法。看起来你的version.txt只包含你想要的数据(没有多余的html),所以我们可以直接下载。如果您需要解析html,我会使用。用于启动的未经测试的代码:
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
Using wc as New WebClient()
Dim version = wc.DownloadString("www.realmofthemadgod.com/version.txt")
Dim swf = "http://www.realmofthemadgod.com/AssembleeGameClient" + version + ".swf"
wc.DownloadFile(swf,"c:\temp\myswf.swf")
End Using
End If
End Sub
谢谢你的快速回复。我一到家就去看看。我还将看一看您提到的包,因为我将需要解析一个html应用程序中的html数组。WebClient是在后台工作,还是导致另存为对话框出现在前端?它在后台工作。如果您不想在请求过程中阻止ui,还可以使用异步版本。