如何提取网页上的数据?

tjhyzg 2009-09-05 10:00:22
<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'


我想提取货币资金后面得7,107,315,888,不知道怎么弄,请高手指教
...全文
346 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
老纳要还俗鸟 2009-09-05
  • 打赏
  • 举报
回复

再给你一个能用的截取函数

'通用截取函数

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> ")



像你这种格式的,还是用楼上的代码读表格来得容易一些

老纳要还俗鸟 2009-09-05
  • 打赏
  • 举报
回复

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
孤独剑_LPZ 2009-09-05
  • 打赏
  • 举报
回复
这是一个办法
s="网页源代码"
i = InStr(s, "货币资金")
s1 = Right(s, Len(s) - i - 16)
j = InStr(s1, "</td><td>")
s2 = Left(s1, j - 1)
t = s2
MsgBox "货币资金:" & t
i = InStr(s, "短期投资净额")
s1 = Right(s, Len(s) - i - 18)
j = InStr(s1, "</td><td>")
s2 = Left(s1, j - 1)
t = s2
MsgBox "短期投资净额:" & t
tjhyzg 2009-09-05
  • 打赏
  • 举报
回复
这个,用代码怎么实现呢
hanvan 2009-09-05
  • 打赏
  • 举报
回复
读取到某个字符串变量中,然后搜索"货币资金",把前面的截掉。
然后搜索第一个<td>,在</td>之间的数字就是你想要的。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧