为什么VB程序不能下载网页上的彩票开奖数据?大家帮帮忙啊!
胜福利 2008-12-20 11:47:41 我参考网上别人的代码编写了下面的程序,但不知为什么下面的VB程序不能下载网页上的彩票开奖数据,哪位网友知道的请帮帮忙!!!!有其他代码参考的请贴上来或给网址都可以.
谢谢!!!
'为运行本程序,应在“菜单->工程->部件”中添加“Microsoft Internet Controls”
'并在“菜单->工程->引用”中添加“Microsoft HTML Object Library”
'添加WebBrowser1控件和文本框控件各一个
Private Sub Form_Load()
On Local Error Resume Next
dim sURL as string
sURL="http://www.sslcp.com/foreground/lottery/3dc/3dhistoryNum.jsp"
WebBrowser1.Navigate sURL '打开下载数据网页地址
End Sub
'下载工作
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
' 当前网址为空或正在加载URL
If WebBrowser1.LocationURL = "http:///" Or WebBrowser1.LocationURL = "" Or WebBrowser1.Busy = True Then Exit Sub
On Local Error Resume Next
Dim i As Long
Dim j As Long
Dim strShuJu as string
'网页表格对象变量
Dim Tables As IHTMLElementCollection
Dim Table1 As HTMLTable '用HTMLTable对象来处理每个Table
Dim Row As HTMLTableRow, Cell As HTMLTableCell ' HTMLTableRow对象和HTMLTableCell对象
'●
For i = 0 To WebBrowser1.Document.Forms(1).length - 1
Set Tables = WebBrowser1.Document.getElementsByTagName("Table") '收集网页上所有的 Table
For Each Table1 In Tables ' 读取网页所有的数据表格
If Left$(Table1.innerText, 6) = "期号中奖号码" Then '由标题行字段找到表
'●
For i = 2 To Table1.rows.length - 1 ' 从第2行开始读取数据
Set Row = Table1.rows(i) '表格的每条记录行
j = 0 '每行都从第0单元格开始读数据
For Each Cell In Row.cells ' 逐列处理
strShuJu = Trim$(Row.cells(j).innerText) '当前单元数据
Text1.text = Text1.text & strShuJu & " " '空格串
j = j + 1 ' 读取下一列
If j = 2 Then
Text1.text = Text1.text & vbCrLf '每行结束要换新行
Exit For '只要读取期号和开奖号码
End If
Next
Next
'●
Exit For '完成网页中表格数据下载则跳出循环
End If
Next
End Sub