关于抓取webbrowser图片链接。
我在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
答案 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
这是输出: