如何在Visual Basic应用程序中获取特定URL的源代码?

时间:2017-04-22 03:54:20

标签: vb.net

我正在尝试使用的当前方法是:

    Public Class Form1
Private Sub btnRead_Click(sender As Object, e As EventArgs) Handles btnRead.Click
    Dim url As String = txtUrl.Text
    output.Items.Add(url)
    WebBrowser1.Navigate(url)
    output.Items.Add(WebBrowser1.DocumentText)

End Sub
End Class

我非常有信心这会起作用,但我的App证明不是......有什么帮助吗?

2 个答案:

答案 0 :(得分:2)

没关系,我使用了不同的方法:

    Imports System.Net
Public Class Form1
Private Sub btnRead_Click(sender As Object, e As EventArgs) Handles btnRead.Click
    Dim Client As New WebClient()
    Dim url As String = txtUrl.Text

    Dim html As String = Client.DownloadString(New Uri(url))
    output.Text = html

End Sub

结束班

这完美无缺。如果你想知道,输出是RichTextBox。

答案 1 :(得分:0)

尝试WebBrowser1.Document.Body.InnerHTML