|
Sub Get_Weather() '天气温度获取
Dim xmlHttp As Object '创建对象
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "GET", "https://www.weaoo.com/nantong-haimenshi-417.html", False '发送请求
xmlHttp.send
Do While xmlHttp.ReadyState <> 4 '等待响应
DoEvents
Loop
Dim Myhtml As String
Myhtml = xmlHttp.responseText '得到请求数据
Dim weather As String
weather = Replace(Split(Split(Myhtml, "<i class=""wi wi-night-cloudy""> </i>")(1), "</span>")(0), Chr(10), "")
Weathers = Split(Replace(weather, " ", ""), "/")
MsgBox ("今日温度:" & Weathers(0))
End Sub
Sub Orient_Weather() '天气温度获取
OrientDate = "2023/5/1"
HtmlDate = Format(OrientDate, "YYYYMM")
StrDate = Format(OrientDate, "YYYY-MM-DD")
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
weather = Split(Split(Myhtml, "<div class=""th200"">" & StrDate)(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 "当前日期当时星期:" & Weathers(0)
Debug.Print "当前日期最高温度:" & Weathers(1)
Debug.Print "当前日期最低温度:" & Weathers(2)
Debug.Print "当前日期天气信息:" & Weathers(3)
Debug.Print "当前日期风向风级:" & Weathers(4)
End Sub
自行测试,可以指定日期获得当前天气 |
评分
-
1
查看全部评分
-
|