以前用VB6写过一个枚举程序,总是觉得不是很直观,这次用VB.NET写可能要好一点,但是也存在一些问题,例如没有枚举父,没有提供测试功能。简要的写几句,其实对照HTML代码就可以了,只是为了解决有得页面比较复杂或者运行脚本导致查看源码看到的东东不全的问题。
非常简单,一按钮,一个文本框,一panel,一webbrowser。将panel拖动到页面元素上文本框里就显示内容了,不过一般还是拖动到其父上,效果比较好——可以看到代码。
Public Class Form1
Dim GetObj As Boolean
Dim HtmlObj As HtmlElement
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Web.Navigate(InputBox("请输入网址,例如:http://www.163.com/", "导航到", "http://gz2010.qlteacher.com/"))
End Sub
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
GetObj = True
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If GetObj Then
Dim PointFromWeb As Point = Web.PointToClient(MousePosition)
Dim tmp As HtmlElement = Web.Document.GetElementFromPoint(PointFromWeb)
If Not tmp.Equals(HtmlObj) Then
HtmlObj = tmp
Me.Text = PointFromWeb.ToString & " ---------- " & HtmlObj.OffsetRectangle.Size.ToString
TextBox1.Text = HtmlObj.InnerHtml
End If
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
GetObj = False
End Sub
End Class
就是记录一下,其实什么技术也没有,以后用的时候方便,最近要求在网上做一些无聊的事情,恐怕自动化更好。。。。