1

关于捕获 webbrowser 图片链接。
我的网络浏览器只有一张图片。
如何将此图像链接捕获到 TextBox 中?
我在 wenBrowser1 属性中设置了网站链接

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
4

2 回答 2

1

穿上WebBrowser1_DocumentCompleted

于 2012-04-29T16:04:44.420 回答
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

这是输出: 在此处输入图像描述

于 2012-04-29T14:10:41.963 回答