作者:绿色风
分类:
时间:2022-08-17
浏览:251
楼主 嘉昆2011 |
主要思路: 利用遍历算法找到相应元素所对应的代号:- Set r = IE.Document.all.tags("标签名称")
- For i = 0 To r.Length-1
- Cells(i + 1, 1) = i
- Cells(i + 1, 2)=r(i).innerText
- Next i
仿制效果:
刷新代码:- Private Sub CommandButton1_Click()
- '****************刷新
- ActiveSheet.Range("theDate") = ""
- ActiveSheet.Range("Update") = ""
- ActiveSheet.Range("HighTemp") = ""
- ActiveSheet.Range("LowTemp") = ""
- ActiveSheet.Range("CurrentTemp") = ""
- ActiveSheet.Range("City") = ""
-
- Dim delShape As Shape
- For Each delShape In ActiveSheet.Shapes
- If delShape.Type = msoAutoShape Then delShape.Delete
- Next delShape
-
- '****************利用IE遍历获取所需数据
- Dim IE As New InternetExplorer
- 'IE.Visible = True
- IE.Navigate "http://www.weather.com/weather/tenday/Honolulu+HI+USHI0026:1:US", False
- Do
- DoEvents
- Loop Until IE.ReadyState = READYSTATE_COMPLETE
-
- Set r = IE.Document.all.tags("h3")
- For i = 8 To 13
- Range("theDate").Cells(i - 7, 1) = Split(Trim(r(i).innerText), " ")(1) _
- & Split(Trim(r(i).innerText), " ")(2)
- Next i
-
- Set s = IE.Document.all.tags("p")
- Range("Update").Value = Split(Trim(s(1).innerText), " HST")
- For i = 5 To 21
- n = i Mod 3
- If n = 2 Then
- Range("HighTemp").Cells(Int((i - 4) / 3) + 1, 1) = Split(Trim(s(i).innerText), "F")
- ElseIf n = 0 Then
- Range("LowTemp").Cells(Int((i - 4) / 3) + 1, 1) = Split(Trim(s(i).innerText), "F")
- Else
- i = i
- End If
- Next i
-
- Range("City") = Split(Trim(IE.Document.all.tags("h1")(0).innerText), " ")
- Range("CurrentTemp") = Split(Trim(IE.Document.all.tags("li")(58).innerText), "F")
- Dim wShape As Shape
- Dim theCell As Range
-
- Set t = IE.Document.all.tags("img")
- For i = 3 To 8
- Set theCell = Range("PicWeather").Cells(i - 2, 1)
- Set wShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, _
- 1.02 * theCell.Left, theCell.Top, 0.78 * theCell.Width, 0.9 * theCell.Height)
- wShape.Fill.UserPicture IE.Document.images(i).src
- Next i
- Set theCell = Range("CPWeather")
- Set wShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, _
- 0.94 * theCell.Left, 0.85 * theCell.Top, 1.5 * theCell.Width, 3.5 * theCell.Height)
- wShape.Fill.UserPicture IE.Document.images(1).src
- '****************美化格式
- For Each wShape In ActiveSheet.Shapes
- If wShape.Type = msoAutoShape Then wShape.Line.Visible = msoFalse
- Next wShape
-
- '****************退出IE
- IE.Quit
-
- End Sub
利用网页抓取数据,推荐阅读: http://www.exceltip.net/thread-39369-1-1.html
天气数据抓取相关例子: http://www.exceltip.net/thread-31761-1-1.html
http://www.exceltip.net/thread-33439-1-1.html
附件:
Weather.rar
|
2楼 xyf2210 |
很好很强大呀 |
3楼 嘉昆2011 |
谢谢支持哦 |
4楼 千年一梦遥 |
昆哥好强大! |
5楼 嘉昆2011 |
谢谢一梦支持 |
6楼 HIMYM |
这都可以? 佩服 |
7楼 arcsinf |
怎么不能刷新呢 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一