ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E文精选 > Excel VBA > iPad/iPhone天气预报界面

iPad/iPhone天气预报界面

作者:绿色风 分类: 时间:2022-08-17 浏览:162
楼主
嘉昆2011
主要思路:
利用遍历算法找到相应元素所对应的代号:
  1. Set r = IE.Document.all.tags("标签名称")
  2.     For i = 0 To r.Length-1
  3.         Cells(i + 1, 1) = i
  4.         Cells(i + 1, 2)=r(i).innerText
  5.     Next i
仿制效果:

 

刷新代码:
  1. Private Sub CommandButton1_Click()

  2. '****************刷新
  3.     ActiveSheet.Range("theDate") = ""
  4.     ActiveSheet.Range("Update") = ""
  5.     ActiveSheet.Range("HighTemp") = ""
  6.     ActiveSheet.Range("LowTemp") = ""
  7.     ActiveSheet.Range("CurrentTemp") = ""
  8.     ActiveSheet.Range("City") = ""
  9.    
  10.     Dim delShape As Shape
  11.     For Each delShape In ActiveSheet.Shapes
  12.         If delShape.Type = msoAutoShape Then delShape.Delete
  13.     Next delShape
  14.    
  15. '****************利用IE遍历获取所需数据
  16.     Dim IE As New InternetExplorer
  17.     'IE.Visible = True
  18.     IE.Navigate "http://www.weather.com/weather/tenday/Honolulu+HI+USHI0026:1:US", False
  19.     Do
  20.     DoEvents
  21.     Loop Until IE.ReadyState = READYSTATE_COMPLETE
  22.    
  23.     Set r = IE.Document.all.tags("h3")
  24.     For i = 8 To 13
  25.         Range("theDate").Cells(i - 7, 1) = Split(Trim(r(i).innerText), " ")(1) _
  26.         & Split(Trim(r(i).innerText), " ")(2)
  27.     Next i
  28.    
  29.     Set s = IE.Document.all.tags("p")
  30.     Range("Update").Value = Split(Trim(s(1).innerText), " HST")
  31.     For i = 5 To 21
  32.         n = i Mod 3
  33.         If n = 2 Then
  34.             Range("HighTemp").Cells(Int((i - 4) / 3) + 1, 1) = Split(Trim(s(i).innerText), "F")
  35.         ElseIf n = 0 Then
  36.             Range("LowTemp").Cells(Int((i - 4) / 3) + 1, 1) = Split(Trim(s(i).innerText), "F")
  37.         Else
  38.             i = i
  39.         End If
  40.     Next i
  41.      
  42.     Range("City") = Split(Trim(IE.Document.all.tags("h1")(0).innerText), " ")
  43.     Range("CurrentTemp") = Split(Trim(IE.Document.all.tags("li")(58).innerText), "F")

  44.     Dim wShape As Shape
  45.     Dim theCell As Range
  46.      
  47.     Set t = IE.Document.all.tags("img")
  48.     For i = 3 To 8
  49.         Set theCell = Range("PicWeather").Cells(i - 2, 1)
  50.         Set wShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, _
  51.         1.02 * theCell.Left, theCell.Top, 0.78 * theCell.Width, 0.9 * theCell.Height)
  52.         wShape.Fill.UserPicture IE.Document.images(i).src
  53.     Next i
  54.     Set theCell = Range("CPWeather")
  55.     Set wShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, _
  56.     0.94 * theCell.Left, 0.85 * theCell.Top, 1.5 * theCell.Width, 3.5 * theCell.Height)
  57.     wShape.Fill.UserPicture IE.Document.images(1).src

  58. '****************美化格式
  59.     For Each wShape In ActiveSheet.Shapes
  60.         If wShape.Type = msoAutoShape Then wShape.Line.Visible = msoFalse
  61.     Next wShape
  62.    
  63. '****************退出IE
  64.     IE.Quit
  65.    
  66. 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总版主之一

评论列表
sitemap