vb.net:关于抓住webbrowser图片链接

时间:2012-04-29 12:53:27

标签: vb.net

关于抓取webbrowser图片链接。 我的网页浏览器有一个图像 如何将此图像链接捕获到TextBox?
我在webBrowser1属性

中设置了网站链接
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
        For Each CurElement As HtmlElement In PageElements
            TextBox1.Text = TextBox1.Text & CurElement.GetAttribute("src") & Environment.NewLine
        Next
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

2 个答案:

答案 0 :(得分:1)

将其放在WebBrowser1_DocumentCompleted

答案 1 :(得分:0)

我认为这就是你需要的东西?

添加Webbrowser控件,2 button控件和textbox控件,并将textbox属性设置为multiline

当您第一次点击button1时,您将导航到您的某个网站。

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("http://www.microsoft.com")
End Sub

当您点击button2时,该网络链接中的所有图片都将添加到您的文本框

Private Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
    Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
    For Each CurElement As HtmlElement In PageElements
        TextBox1.Text = TextBox1.Text & CurElement.GetAttribute("src") & Environment.NewLine
    Next
End Sub

这是输出: enter image description here