7,763
社区成员
发帖
与我相关
我的任务
分享
'通用截取函数
Public Function strCut( strContent As String, StrStart As String, StrEnd As String) As String
Dim strHtml, s1, S2 As String
strHtml = strContent
On Error Resume Next
If InStr(strHtml, StrStart) = 0 Then
strCut = ""
Else
s1 = InStr(strHtml, StrStart) + Len(StrStart)
S2 = InStr(s1, strHtml, StrEnd)
strCut = Mid$(strHtml, s1, S2 - s1)
End If
End Function
SourceHtml="<tr> <td width='150px'> <strong>报告期 </strong> </td> <td>2009-06-30 </td> <td>2009-03-31 </td> <td>2008-12-31 </td> <td>2008-09-30 </td> </tr> <tr> <td colspan='5'> <strong>资产 </strong> </td> </tr> <tr> <td colspan='5'> <strong>流动资产 </strong> </td> </tr> <tr> <td width='150px'> <a target='_blank' href='/corp/view/vFD_FinanceSummaryHistory.php?stockid=600827&type=hbzj'>货币资金 </a> </td> <td>7,107,315,888 </td> <td>7,461,738,198 </td> <td>7,102,736,371 </td> <td>6,074,186,310 </td> </tr> <tr> <td width='150px'> <a target='_blank' href='/corp/view/vFD_FinanceSummaryHistory.php?stockid=600827&type=dqtz'>短期投资 </a> </td> <td>0 </td> <td>0 </td> <td>0 </td> <td>0 </td> </tr> <tr> <td width='150px'> <a target='_blank'
"
ret=strCut(SourceHtml,"货币资金 </a> </td> <td>","</td> ")
Option Explicit
Dim Page As Long
Dim Table1 As HTMLTable, Tables As IHTMLElementCollection
Dim Row As HTMLTableRow, Cell As HTMLTableCell
Dim i, j, tmp
Dim text1, text2 As String
Private Sub Command1_Click()
Set Tables = WebBrowser1.Document.getElementsByTagName("Table")
For Each Table1 In Tables
If Left(Table1.innerText, 2) = "币种" 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
MsgBox "数据采集成功"
Exit For
End If
Next
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.icbc.com.cn/ICBCDynamicSite/Optimize/Quotation/QuotationListIframe.aspx?variety=1&publishDate=2008-12-31" ' 起始网址
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
' 判断当前网页是否全部调入完毕
If Not (pDisp Is WebBrowser1.Object) Then Exit Sub
End Sub