|
代码如下:
Function 获取天气()
Dim txt, a, b
Dim web1
'On Error Resume Next
web1 = "http://www.weather.com.cn/weather/101010100.shtml"
Application.ScreenUpdating = False
Set web = CreateObject("MSXML2.XMLHTTP")
web.Open "Get", Trim(web1), False
web.Send
txt = web.responsetext
a = InStr(1, txt, "<div id=""7d"" class=""c7d"">")
b = InStr(1, txt, "<div class=""btn"">")
txt = "<table>" & HtmlFilter(txt, "<ul class=""t clearfix"">", "<i class=""line1"">") & "</table>"
Cells(1, 1).Select
PutClipboard txt
ActiveSheet.Paste
MsgBox "完成!"
End Function
Public Function HtmlFilter(ByVal htmlText$, Label1$, label2$)
'返回html字符串lable1和最近的lable2标签中的数据
Dim pStart As Long, pStop As Long
'开始位置,结束位置
pStart = InStr(htmlText, Label1) + Len(Label1)
'找到标签信息的起始位置
If pStart <> 0 Then
pStop = InStr(pStart, htmlText, label2)
HtmlFilter = Mid(htmlText, pStart, pStop - pStart)
End If
End Function
Public Sub PutClipboard(ByVal tt$) 'tt放入剪贴板
With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") '调试用,数据放入剪贴板
.SetText tt
.PutInClipboard
End With
End Sub
|
|