|
不难,仅供参考
第一种 ;split 第二种 正则
- Sub ccmn()
- Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
- Url = "https://www.ccmn.cn/index_table/"
- With winhttp
- .Open "GET", Url, False
- .send
- strText = .responseText
- If InStr(strText, "<td>1#铜</td>") Then
- aa = Split(Split(strText, "<td>1#铜</td>")(1), "</tr>")(0)
- bb = Split(Replace(Replace(aa, " ", ""), vbLf, ""), "<td>")
- ReDim arr(1 To 1, 1 To 4)
- arr(1, 1) = "1#铜" ''品名
- arr(1, 2) = Val(Split(bb(2), "<")(0)) ''均价
- arr(1, 3) = Val(Split(Split(bb(2), """>")(1), "<")(0)) ''涨跌
- arr(1, 4) = Split(bb(4), "<")(0) ''日期
- '' a1开始写入
- Sheet1.[a1].Resize(1, 4) = arr
- End If
- End With
- Set winhttp = Nothing
- End Sub
- Sub ccmn1()
- Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
- Url = "https://www.ccmn.cn/index_table/"
- Set reg = CreateObject("vbscript.regexp")
- reg.Pattern = "(-)|(</)|\n|\s|\D"
- reg.Global = True
- With winhttp
- .Open "GET", Url, False
- .send
- strText = .responseText
- If InStr(strText, "<td>1#铜</td>") Then
- aa = Split(Split(strText, "<td>1#铜</td>")(1), "</tr>")(0)
- mm = reg.Replace(aa, "$1$2")
- bb = Split(mm, "</")
- ReDim arr(1 To 1, 1 To 4)
- arr(1, 1) = "1#铜" ''品名
- arr(1, 2) = Val(bb(1)) ''均价
- arr(1, 3) = Val(bb(2)) ''涨跌
- arr(1, 4) = bb(4) ''日期
- '' a2开始写入
- Sheet1.[a2].Resize(1, 4) = arr
- End If
- End With
- Set reg = Nothing
- Set winhttp = Nothing
- End Sub
复制代码
|
-
|