|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub Orient_Weather() '天气温度获取
OrientDate = "2023/7/9"
HtmlDate = Format(OrientDate, "YYYYMM")
HtmlMonth = Format(OrientDate, "YYYY-MM")
Dim xmlHttp As Object '创建对象
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "GET", "https://lishi.tianqi.com/nantong/" & HtmlDate & ".html", False '发送请求
xmlHttp.send
Do While xmlHttp.ReadyState <> 4 '等待响应
DoEvents
Loop
Dim Myhtml As String
Myhtml = xmlHttp.responseText '得到请求数据
Dim weather As String
AllDate = Split(Myhtml, "<div class=""th200"">" & HtmlMonth & "-")
For n = 1 To UBound(AllDate)
ThisData = Split(AllDate(n), " 星期")(0)
ThisData = HtmlMonth & "-" & ThisData
weather = Split(Split(Myhtml, "<div class=""th200"">" & ThisData)(1), "</li>")(0)
Weathers = Split(weather, "<div class=""th140"">")
For i = 0 To UBound(Weathers)
Weathers(i) = Split(Weathers(i), "</div>")(0)
Next i
Weathers(0) = Replace(Weathers(0), " ", "") '星期去除前后空格
Debug.Print ThisData & " 当时星期:" & Weathers(0)
Debug.Print ThisData & " 最高温度:" & Weathers(1)
Debug.Print ThisData & " 最低温度:" & Weathers(2)
Debug.Print ThisData & " 天气信息:" & Weathers(3)
Debug.Print ThisData & " 风向风级:" & Weathers(4)
Next n
End Sub
完整的获取每个月每天所有天气的代码,你自己把年份月份做个遍历就行了,目前来说还是好用的 |
评分
-
2
查看全部评分
-
|