怎么提取html的数据,如何提取网页数据

Sub 下载商品现货与期货价格对比数据()

On Error Resume Next

Dim Url, HTML, r

Dim mr, n As Long, i%, j%, d

ActiveSheet.UsedRange.Offset(3).Clear

d = InputBox("请输入开始日期与终止日期", "日期范围", Format(Date, "yyyy-mm-dd/yyyy-mm-dd"))

Set HTML = CreateObject("htmlfile")

With CreateObject("msxml2.xmlhttp")

For n = Format(Split(d, "/")(0), "0") To Format(Split(d, "/")(1), "0")

mr = ActiveSheet.UsedRange.Rows.Count

If n > Format(Split(d, "/")(0), "0") Then Range("1:3").Copy Range("A" & mr + 1)

Range("b" & IIf(n > Format(Split(d, "/")(0), "0"), mr + 1, mr - 2)) = Format(n, "生意社:mm月dd日商品现货与期货价格对比表")

Url = "http://www.100ppi.com/sf/day-" & Format(n, "yyyy-mm-dd") & ".html"

.Open "get", Url, False

.send

HTML.body.innerhtml = .responsetext

Set r = HTML.all.tags("table")(1).Rows

For i = 2 To r.Length - 1

For j = 0 To r(1).Cells.Length

Cells(IIf(n > Format(Split(d, "/")(0), "0"), mr + 1, mr - 2) + i + 1, j + 1) = r(i).Cells(j).innertext

Cells(IIf(n > Format(Split(d, "/")(0), "0"), mr + 1, mr - 2) + i + 1, 5) = Replace(Replace(Split(Split(r(i).Cells(4).innerhtml, "color=")(1), "", ""), "red>", "")

Cells(IIf(n > Format(Split(d, "/")(0), "0"), mr + 1, mr - 2) + i + 1, 8) = Replace(Replace(Split(Split(r(i).Cells(7).innerhtml, "color=")(1), "", ""), "red>", "")

Next j

Next i

Next n

End With

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值