程序代码:
Private Sub Command1_Click()
Command1.Enabled = False
Web.Navigate "http://www.csdn.net"
End SubPrivate Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = Web.Document
For Each i In doc.All
If TypeName(i) = "HTMLTable" Then
Text2.Text = Text2.Text & TypeName(i) & vbclrf
Text1.Text = Text1.Text & VbCrLf & i.innertext
End If
Next
Command1.Enabled = True
End Sub
如果我想提取其中的某个table应该如何提取?还有如何把提取出来的关键字以列表的方式在excel里排序?最后一个就是,提取出好多重复的关键字~如何判断?新手求教~谢谢!
Private Sub Command1_Click()
Command1.Enabled = False
Web.Navigate "http://www.csdn.net"
End SubPrivate Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = Web.Document
For Each i In doc.All
If TypeName(i) = "HTMLTable" Then
Text2.Text = Text2.Text & TypeName(i) & vbclrf
Text1.Text = Text1.Text & VbCrLf & i.innertext
End If
Next
Command1.Enabled = True
End Sub
如果我想提取其中的某个table应该如何提取?还有如何把提取出来的关键字以列表的方式在excel里排序?最后一个就是,提取出好多重复的关键字~如何判断?新手求教~谢谢!
用 webbrowser.document.getElementsByTagName("table")
Command1.Enabled = False
Web.Navigate "http://www.csdn.net"
End SubPrivate Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set Tables = Web.Document.getElementsByTagName("Table")
For Each Table1 In Tables
If Left(Table1.innerText, 2) = "No." Then ' 找到需要的Table
' 将表格转换成“.csv”格式
For i = 1 To Table1.rows.length - 1
Set Row = Table1.rows(i)
j = 0
For Each Cell In Row.cells
Text1 = Text1 + Trim(Row.cells(j).innerText) + ","
j = j + 1
Next
Text1 = Left(Text1, Len(Text1) - 1) + vbCrLf
Next
' 数据存盘
Open "C:\Data.csv" For Append As #1
Print #1, Left(Text1, Len(Text1) - 2): Text1 = "": Close #1
Exit For
End If
Next
' 准备打开下一页
Page = Page + 1
tmp = "http://www.csdn.net"
If Page <= 2 Then ' 判断是否浏览结束
WebBrowser1.Navigate tmp
End If
End Sub
调试的时候Set Tables = Web.Document.getElementsByTagName("Table") 是黄色的 错误信息:对象变量或with块变量未设置
帮帮忙 debug下~谢谢
Private Sub Command1_Click()
Command1.Enabled = False
WebBrowser1.Navigate "http://www.csdn.net"
End SubPrivate Sub webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set Tables = WebBrowser1.Document.getElementsByTagName("Table")
For Each Table1 In Tables
If Left(Table1.innerText, 2) = "No." Then ' 找到需要的Table
' 将表格转换成“.csv”格式
For i = 1 To Table1.rows.length - 1
Set Row = Table1.rows(i)
j = 0
For Each Cell In Row.cells
Text1 = Text1 + Trim(Row.cells(j).innerText) + ","
j = j + 1
Next
Text1 = Left(Text1, Len(Text1) - 1) + vbCrLf
Next
' 数据存盘
Open "C:\Data.csv" For Append As #1
Print #1, Left(Text1, Len(Text1) - 2): Text1 = "": Close #1
Exit For
End If
Next
' 准备打开下一页
Page = Page + 1
tmp = "http://www.csdn.net"
If Page <= 2 Then ' 判断是否浏览结束
WebBrowser1.Navigate tmp
End If
End Sub
Command1.Enabled = False
WebBrowser1.Navigate "http://www.csdn.net"
End SubPrivate Sub webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set tables = WebBrowser1.Document.getElementsByTagName("Table")
MsgBox tables.length
End Sub