前面我们已经分享过一个天气预报的实例。但是可能代码没有完整,很多网友看了都不是很懂。今天继续分享一个天气报告的网抓内容。有多种样式可以选择,可以显示全国天气和分省份显示天气,气温和风力;也可以显示地区的的详细信息:包括舒适度,穿衣,旅游等等内容。
作者:小林子-Office中国Excel天气预报信息城市代码:
1482913293120080.jpg
洛阳天气:
1482913293112257.jpg
河南天气:
1482913294586351.jpg
全国天气:
1482913294742513.jpg
Excel天气预报详细VBA代码: Sub 全国天气() On Error Resume Next Dim objXML As Object Dim txtContent As String Dim arrT1() As String Dim arrT2() As String Dim arrT3(1 To 37, 1 To 4) As String Dim i As Integer Application.ScreenUpdating = False Range("A1:D38") = "" Range("A1:D1") = Array("城市", "天气", "气温(℃)", "风力") Set objXML = CreateObject("Microsoft.XMLHTTP") With objXML .Open "GET", "http://flash.weather.com.cn/wmaps/xml/china.xml", False .send If objXML.Status = 200 Then txtContent = .responsetext arrT1 = Split(txtContent, "") arr2 = Split(arr1(1), "") arr3 = Split(arr1(1), "") Range("A1") = "洛阳天气:今天是 " & Format(Now(), "YYYY 年 M 月 D 日") & " " & Format(Now(), "aaaa") For i = 1 To 5 arr4 = Split(arr2(i), ">")
Cells(i + 2, 1) = Format(Now() + i - 1, "M 月 D 日") Cells(i + 2, 2) = Left(arr4(8), Len(arr4(8)) - 6) Cells(i + 2, 3) = Mid(arr4(5), 4, Len(arr4(5)) - 9) & " ~ " & Mid(arr4(3), 4, Len(arr4(3)) - 10) Cells(i + 2, 4) = Left(arr4(10), Len(arr4(10)) - 11) & Left(arr4(12), Len(arr4(12)) - 8) Next i arr6 = Split(txtContent, "") arr7 = Split(txtContent, "") Cells(6, 8) = "↑" & Left(arr6(1), 5) Cells(7, 8) = "↓" & Left(arr7(1), 5) For j = 1 To 11 arr5 = Split(arr3(j), "点击加入群:Excel部落结识Excel大神学好Excel,效率成倍提高,薪水稳步增长,职位快速提升
每天一个源创技巧,如觉得有用,请点上面关注。更重要手机转发分享 |