ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 11079|回复: 20

[已解决] 抓取 天气网站 历史数据!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2015-10-20 14:25 | 显示全部楼层 |阅读模式
求助~我希望从http://tianqi.2345.com/wea_history/59287.htm涉及到广州的2015年天气信息记录在excel里面,希望各位大侠帮忙,可以的话把解释标注一下。。。不想单纯的抄袭。。但找了很久资料又没有方向。。。当然手动是可以。但是我是需要多个城市的资料以及定期更新,手动粘贴太。。。

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-10-20 15:43 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2015-10-20 22:25 | 显示全部楼层
请测试
  1. Sub Weather()
  2.     Dim strText As String
  3.     Cells.Clear
  4.     With CreateObject("MSXML2.XMLHTTP")
  5.             .Open "GET", "http://www.tianqihoubao.com/weather/top/guangzhou.html", False
  6.             .setRequestHeader "Connection", "keep-alive"
  7.             .Send
  8.             strText = .responsetext
  9.             strText = "<table" & Split(Split(strText, "<table")(1), "</table>")(0) & "</table>"
  10.             
  11.             With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  12.                 .SetText strText
  13.                 .PutInClipboard
  14.             End With
  15.             
  16.             Range("A1").Select
  17.             ActiveSheet.Paste
  18.             
  19.     End With
  20. End Sub
复制代码

评分

3

查看全部评分

TA的精华主题

TA的得分主题

发表于 2015-10-20 23:06 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2015-10-20 23:31 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
请教!出现这些乱码,怎么修改!
  1.    
  2.     Application.ScreenUpdating = 0
  3.    
  4.     Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
  5.     With xmlhttp
  6.         .Open "get", "http://tianqi.2345.com/t/wea_history/js/59287_201510.js", False
  7.         .send
  8.         t = .responsetext
  9.         t1 = Replace(Split(Split(t, "[{ymd:")(1), "{}]")(0), "ymd:", Chr(10))
  10.         t1 = Replace(t1, "',", ",")
  11.         
  12.     End With
  13.    
  14.     Debug.Print Left(t1, 2000) '& Right(t1, 2000)
  15.    
  16.     With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  17.         .SetText t1
  18.         .PutInClipboard
  19.     End With

  20.     With ActiveSheet
  21.         .[a4].Select
  22.         .Paste
  23.         .[a4:a35].TextToColumns Destination:=Range("a4"), Comma:=True
  24.     End With
  25.    
  26.     Set winhttp = Nothing
  27.     Application.StatusBar = False
  28.     Application.ScreenUpdating = True
  29.    
  30. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2015-10-20 23:38 | 显示全部楼层
amzxfgh9632 发表于 2015-10-20 23:06
http://www.tianqihoubao.com/yubao/beijing.html   含图片和表头不知道能不能做哦

谢谢加分!我也是才学网抓!试试看!

TA的精华主题

TA的得分主题

发表于 2015-10-20 23:42 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2015-10-20 23:58 | 显示全部楼层
amzxfgh9632 发表于 2015-10-20 23:06
http://www.tianqihoubao.com/yubao/beijing.html   含图片和表头不知道能不能做哦

请测试!先来无图片的!有图片的还在学习研究下!
  1. Sub Weather_forecast() 'http://www.tianqihoubao.com/lishi/guangzhou/month/201509.html
  2.     Dim strText As String
  3.     Cells.Clear
  4.     With CreateObject("MSXML2.XMLHTTP")
  5.             .Open "GET", "http://www.tianqihoubao.com/yubao/beijing.html", False
  6.             .setRequestHeader "Connection", "keep-alive"
  7.             .send
  8.             strText = .responsetext
  9.             [a1] = Split(Split(strText, "<h1>")(1), "</h1>")(0)
  10.             [a2] = "数据为" & Split(Split(strText, "数据为")(1), "</div>")(0)
  11.             strText = "<table" & Split(Split(strText, "<table")(1), "</table>")(0) & "</table>"
  12.             strText = Replace(strText, "img src='/legend/", "")
  13.             With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  14.                 .SetText strText
  15.                 .PutInClipboard
  16.             End With
  17.             
  18.             Range("A3").Select
  19.             ActiveSheet.Paste
  20.             
  21.     End With
  22. End Sub
复制代码

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2015-10-21 00:45 | 显示全部楼层
amzxfgh9632 发表于 2015-10-20 23:42
http://www.15tianqi.com/beijing/抓这个15天的,要含图片哦

来个简单的先!好困啦!改日再学习着做一下
  1. Sub Weather_forecast15() 'http://www.tianqihoubao.com/lishi/guangzhou/month/201509.html
  2. 'http://www.15tianqi.com/beijing/
  3.     Dim strText As String
  4.     Cells.Clear
  5.     With CreateObject("MSXML2.XMLHTTP")
  6.             .Open "GET", "http://www.15tianqi.com/beijing/", False
  7.             .setRequestHeader "Connection", "keep-alive"
  8.             .send
  9.             strText = .responsetext
  10.             [a1] = Split(Split(strText, "<h1>")(1), "</h1>")(0)
  11.             strText = Split(Split(strText, "未来15天天气预报★")(1), "由15tianqi.com")(0)
  12.             strText = Replace(strText, ":" & Chr(13) & Chr(10), Chr(9))
  13.             strText = Replace(strText, Chr(13) & Chr(10), "")
  14.             strText = Replace(Replace(strText, ",", Chr(9)), " ", "")
  15.             
  16.             Debug.Print strText
  17.             With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  18.                 .SetText strText
  19.                 .PutInClipboard
  20.             End With
  21.             
  22.             Range("A2").Select
  23.             ActiveSheet.Paste
  24.             '[a3:a35].TextToColumns Destination:=Range("a3"), Comma:=True

  25.             
  26.     End With
  27. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2015-10-21 10:01 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

我想在http://tianqi.2345.com/wea_history/59287.htm这个网站下载数据。。。并且可以拿到历史月份的数据。。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-20 11:25 , Processed in 0.048822 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表