数码之家

 找回密码
 立即注册
搜索
查看: 4617|回复: 15

[ARM] 请问各位大神,ESP8266访问网站,由于返回数据过多,没法输出全部数据。

[复制链接]
发表于 2019-8-6 21:27:54 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问各位大神,ESP8266访问网站,由于返回数据过多,没法输出全部数据。如何处理?
由于LED彩屏时钟所访问的天气网站数据不准(特别这几天,如今天显示多云,但实际是雷雨),而且有限制,想改用https://www.tianqi.com/beijing/这个网站,但查看它的源码,数据十分多,用ESP8266访问了一下,通过串口把收到的数据发送出来检查,发现输出只有十分一的数据,如下图第一张图是ESP8266串口输出的数据,第二张图页面的源码,需要的数据在中间处,没法提取,不知各位大神有什么方法处理?主要是想能用ESP8266直接处理,把收到的数据整理成所需的数据,如确实没法用ESP8266直接处理,可能会考虑用虚拟服务器访问天气网站,处理好后再由ESP8266访问这台服务器,但这样做法多了个中间件,程序只能自己用而不能公开,没法方便大家。
12345.jpg
1234578.jpg

发表于 2019-8-6 21:37:33 | 显示全部楼层
获取天气,你要访问网站的API,而不是直接访问网页。API会返回数据,一般收拾JSON,用JSON解析就可以了。
回复 支持 反对

使用道具 举报

发表于 2019-8-6 22:02:30 | 显示全部楼层
获取数据是用的api,直接打开网站从中间抓取那是网络爬虫。
回复 支持 反对

使用道具 举报

发表于 2019-8-6 23:10:35 来自手机浏览器 | 显示全部楼层
接收一个判断一个遇到需要的拷贝
不要全部接收了再来判断不然内存不够
回复 支持 1 反对 0

使用道具 举报

发表于 2019-8-7 12:47:52 来自手机浏览器 | 显示全部楼层
netbeetle 发表于 2019-8-6 21:37
获取天气,你要访问网站的API,而不是直接访问网页。API会返回数据,一般收拾JSON,用JSON解析就可以了。 ...

Api有限制,要注册有次数限制,估计楼主是想从网页抓取数据,这网页是自由免费的完全没限制
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-8-7 16:43:28 | 显示全部楼层
ploestar 发表于 2019-8-7 12:47
Api有限制,要注册有次数限制,估计楼主是想从网页抓取数据,这网页是自由免费的完全没限制 ...

对的,就是这个想法。
回复 支持 反对

使用道具 举报

发表于 2019-8-7 16:47:36 | 显示全部楼层
把数据缓存到SPIFF上去。
或者读到关键字以后再缓存。
缓存可以设得大一点。
回复 支持 反对

使用道具 举报

发表于 2019-8-13 14:38:49 | 显示全部楼层
本帖最后由 sadate 于 2019-8-13 14:42 编辑

@落叶风 大侠,我试验了下面的方法,可以极大地减少接收无关的数据量, 应该能满足你的要求:

http://i.tianqi.com/index.php?c=code&a=getcode&id=41&py=mentougou (红色部分改为你需要天气信息的地点的拼音)
2019-08-13_144043.jpg
反馈的数据量如下:(红色部分是你需要过滤出来的数据)
<html   ><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>门头沟天气预报代码调用</title>
<style type="text/css">
<!--
a:link {
    color: #000000;
    text-decoration: none;
}
a:visited {
    text-decoration: none;
    color: #000000;
}
a:hover {
    text-decoration: none;
    color: #000000;
}
a:active {
    text-decoration: none;
    color: #000000;
}
-->
</style></head>
<script type="text/javascript" src="//lib.sinaapp.com/js/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
var color = bgcolor = bdcolor = site = icon = "";
var num = 0;
$(document).ready(function(){
    if (typeof(icon) != 'undefined' && icon != '') {
        $("img.pngtqico").each(function(i){
            this.src = this.src.replace("images/tianqi", "images/" + icon);
        });
    }
    if (typeof(bgcolor) != 'undefined' && bgcolor != '') {
        $("#myscroll").css('background-color', bgcolor);
    }
    if (typeof(bdcolor) != 'undefined' && bdcolor != '') {
        $("#myscroll").css('border', '1px solid ' + bdcolor);
    }
    if (typeof(color) != 'undefined' && color != '') {
        $("#myscroll li a").css('color', color);
    }
});
</script>
<body>
<div style="width:100%;height:20px;font-size:12px; line-height:20px; text-align:left">
        <a target="_blank"  href="http://beijing.tianqi.com/mentougou/?tq" title="门头沟天气预报,点击查看门头沟未来七天天气预报 ">
            <strong>门头沟</strong> 今:
            33-
            23℃            阴;明:
            33-
            21℃
            多云;后:
            32-
            22℃
            晴
   </a>
    </div>


<div style="display: none;">
    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?86f43783acc56b0c8abb5bb039edc763";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
    <script type="text/javascript" src="https://s5.cnzz.com/z_stat.php?id=1277635480&web_id=1277635480"></script>
</div>
</body>
</html>
<script type="text/javascript">num=0;temp=0;</script>



打赏

参与人数 1家元 +20 收起 理由
落叶风 + 20

查看全部打赏

回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-8-13 15:57:11 | 显示全部楼层
sadate 发表于 2019-8-13 14:38
@落叶风 大侠,我试验了下面的方法,可以极大地减少接收无关的数据量, 应该能满足你的要求:

http://i.tia ...

多谢了,试一下,这数据可以处理,但天气数据太少了,如有当前温湿度、风向等等就可用了,我利用你的方法再试一下,看看能不能找得到。
回复 支持 反对

使用道具 举报

发表于 2019-8-13 16:36:55 | 显示全部楼层
本帖最后由 sadate 于 2019-8-13 18:13 编辑

那就试试这个,看看返回数据量是否超标 (标红部分改为你要的地名的拼音)
http://i.tianqi.com/index.php?c=code&a=getcode&id=83&py=mentougou

2019-08-13_163543.jpg
返回数据:(标红部分是你要的数据
<html   ><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>门头沟天气预报代码调用</title>
</head>
<style type="text/css">
body{margin:0;padding:0;font-size:12px;font-fanliy:"宋体",arial;}
body, h1, h2, h3, h4, h5, h6, hr, p, dl, dt, dd, ul, ol, li, pre, fieldset, lengend, textarea, th, td{ margin: 0;padding: 0;}
em{font-size: 12px;font-weight: normal;font-style: normal;}
ul{list-style-type:none;margin:0;padding:0;}
li{list-style-type:none;margin:0;padding:0;}
img{border:0;text-align:top;}
a:link,a:visited,a:hover,a:active{color:#333;text-decoration:none;}
a:hover{color:#333;text-decoration:none;}
.fon16 {font-size:16px;}
.fon14 {font-size:14px;}
.fB {font-weight:bold;}
.today_data{ height:176px}
.today_data_w{ width:160px; height:174px; border:1px solid #9adaff; float:left; background:url("//static.tianqistatic.com/static/images/tq_bg.jpg") repeat-x bottom #fff; margin-right:7px}
.today_data_m{ width:330px; height:174px; border:1px solid #9adaff; float:left; background:url("//static.tianqistatic.com/static/images/tq_bg.jpg") repeat-x bottom #Fff;margin-right:7px;}
.tqshow {width:140px;margin:0 auto;text-align:center}
.tqshow h3,.temp h3,.wind h3{ font-family: "微软雅黑", "宋体"; font-size:16px; color:#0d4b94; padding:10px 0 0;}
.tqshow li {line-height:21px;overflow:hidden;}
.tqshow li img {width:54px;height:54px;margin-bottom:1px;}
.cRed, a.cRed:link, a.cRed:visited {color:#c00;}
.cDRed, a.cDRed:link, a.cDRed:visited {color:#c00;font-size:14px;font-weight:bold;}
.cDRed1, a.cDRed1:link, a.cDRed1:visited {font-size:18px;font-weight:bold;color:#CC0000}
.cGreen, a.cGreen:link, a.cGreen:visited {color:#499704;}
.cBlue, a.cBlue:link, a.cBlue:visited {color:#005EAC;}
.cOrange, a.cOrange:link, a.cOrange:visited {color:#ff8800;}
.cWhite, a.cWhite:link, a.cWhite:visited, a.cWhite:hover {color:#fff;text-decoration:none;}
.cYellow, a.cYellow:link, a.cYellow:visited, a.cYellow:hover {color:#FCCC00;text-decoration:none;}
.temp {    width:162px;height:174px;float:left;text-align:center; overflow:hidden;}
.tqshow h3,.temp h3,.wind h3{ font-family: "微软雅黑", "宋体"; font-size:16px; color:#0d4b94; padding:10px 0 0;}
.tqshow li {line-height:21px;overflow:hidden;}
.tqshow li img {width:54px;    height:54px;margin-bottom:1px;}
.weatherDiv1{float:left;width:151px;height:138px;background: url("//static.tianqistatic.com/static/images/wenduji1.gif") no-repeat 45px 4px;margin:0 0 0 7px;display:inline;position:relative; z-index:0;}   
.weatherDiv1 .numN{position:absolute;width:32px;font-size:9px;color:#000;line-height:12px;text-align:right;top:22px;left:18px;font-family:Tahoma;    }
.weatherDiv1 p.bg_sk{background:#99b0d6 no-repeat;width:8px;position:absolute;top: 7px;left:54px;}
.weatherDiv1 .tq24_1{width:120px;text-align:center;display:block;clear:both; line-height:20px;color:#203665;position: absolute;left: 0px;bottom: 2px;}
            .weatherDiv1 .tq24_1 a{ color:#f00;display:block;position:absolute;right:0;margin-top:0px;width:120px;text-align:center;bottom: 0px;}
            .weatherDiv1 .tq24_1 a:hover{color:#f00;text-decoration:underline;}
.weatherDiv1 strong{ font-family:Tahoma, serif;font-weight:bold;font-size:22px;    display:block;float:right;margin-right:10PX;width:85px;text-align:center;left:55px;    position:absolute;top:30px;    color:#0a50a5;}
.weatherDiv1 a{display:block;position:absolute;right:0;    margin-top:30px;width:110px;text-align:center;color:#000;}   
.weatherDiv1 a:hover{text-decoration:none;color:#000;}
.weatherDiv1 span{width:120px;text-align:center;display:block;clear:both; line-height:20px;color:#203665;position: absolute;left: 0px;bottom: 24px;}   
.wind {width:165px;    height:174px;float:left;text-align:center; position:relative; overflow:hidden;}
.weatherDiv2 span{display:block;padding-top:0px;color:#203665; line-height:20px;}
.weatherDiv2 strong    {display:block;    margin-bottom:40px;_margin-bottom:40px;    font-size:12px;margin-top: 40px;font-size: 12px; font-weight: normal;}
.weatherDiv2 a{color:#000;}
.weatherDiv2 a:hover{text-decoration:none;color:#000;}
.weatherDiv2{float:left;width:151px;height:110px;background:url("//static.tianqistatic.com/static/images/n.gif") no-repeat center 0px;display:inline;text-align:center;margin-top:0px;}

.pm25box{float:left;height:26px; line-height:20px; width:190px; text-align:center; color:#333;overflow:hidden;position:absolute; left:-22px;_left:-22px; bottom:0px;}
.pm25box .t1{ color:#08c; margin-right:4px;font-size:12px;}
.pm25box .p1{ background:#090; color:#fff; padding:2px 3px;}
.pm25box .p2{ background:#69DC4E; color:#fff; padding:2px 3px;}
.pm25box .p3{ background:#F9AF4F; color:#fff; padding:2px 3px;}
.pm25box .p4{ background:#DA1B16; color:#fff; padding:2px 3px;}
.pm25box .p5{ background:#B20F50; color:#fff; padding:2px 3px;}
.pm25box .p6{ background:#4E0320; color:#fff; padding:2px 3px;}
</style>
<body>
<div class="today_data">
<div class="today_data_w">
  <div class="tqshow" id="today">
    <h3 style="padding-bottom:0px;">门头沟今天天气</h3>
    <ul>
        <li class="time">08月13日</li>
                    <li class="tqpng_01"><img class='pngtqico' align='absmiddle' src='http://plugin.tianqistatic.com/static/images/tianqibig/b1.png' style='border:0;width:46px;height:46px'/></li>
        <li class="fon14 fB">
            <span id="t_temp"><font color="#f00">33℃</font>~<font color="#4899be">23℃</font></span>
        </li>
        <li class="cDRed">多云</li>
        <li style="height:18px;overflow:hidden">东北风 4级 </li>
    </ul>
  </div>
</div>
<div class="today_data_m">
  <div class="temp">
    <h3>门头沟当前温度</h3>
    <div class="weatherDiv1">
      <div class="numN"> 50-<br>
        25-<br>
        0-<br>
        -25-<br>
        -50- </div>
      <p class="bg_sk" style="height:27px" id="rethigh"></p>
      <div id="rettemp"><strong>32°</strong><span>相对湿度:46%</span></div>
      <div class="tq24_1"><a href="http://beijing.tianqi.com/mentougou/?tq" target="_blank">24小时天气预报</a></div>
    </div>
  </div>
  <div class="wind">
        <h3>风向风力</h3>
        <div class="weatherDiv2" id="retwind" style="background: url('//www.tianqi.com/static/images/ne.gif') no-repeat scroll center 0;">
            <strong>4级</strong><span>东北风</span>
        </div>
               
  </div>
</div>

</div>
<div style="display: none;">
    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?86f43783acc56b0c8abb5bb039edc763";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
    <script type="text/javascript" src="https://s5.cnzz.com/z_stat.php?id=1277635480&web_id=1277635480"></script>
</div>
</body>
</html>
<script type="text/javascript">num=0;temp=0;</script>

打赏

参与人数 1家元 +20 收起 理由
落叶风 + 20

查看全部打赏

回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-8-13 20:36:21 | 显示全部楼层
本帖最后由 落叶风 于 2019-8-13 20:37 编辑
sadate 发表于 2019-8-13 16:36
那就试试这个,看看返回数据量是否超标 (标红部分改为你要的地名的拼音)
http://i.tianqi.com/index.php?c= ...

这个可以,两个地址组合起来用。我有空研究一下先。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-8-23 20:51:47 | 显示全部楼层
sadate 发表于 2019-8-13 16:36
那就试试这个,看看返回数据量是否超标 (标红部分改为你要的地名的拼音)
http://i.tianqi.com/index.php?c= ...

在这贴https://www.mydigit.cn/forum.php ... p;extra=#pid1456346中得到方法,改变ID值可以收到不同数据,ESP8266可以分别处理,有空再重编写LED彩屏时钟的天气接收程序。
回复 支持 反对

使用道具 举报

发表于 2020-3-12 18:17:18 | 显示全部楼层
落叶风 发表于 2019-8-7 16:43
对的,就是这个想法。

试试手机版,把www.换成m.
回复 支持 反对

使用道具 举报

发表于 2020-3-12 23:38:01 来自手机浏览器 | 显示全部楼层
在中国天气页面,选择定制h5,Chrome f12然后在源码里面会有一个调用天气的api,返回的是一个json。https://apip.weatherdt.com/plugin/data?key=6VrYDKzyhb&location=101250101
location是城市代码。
回复 支持 反对

使用道具 举报

发表于 2020-3-13 11:21:53 | 显示全部楼层
ploestar 发表于 2019-8-7 12:47
Api有限制,要注册有次数限制,估计楼主是想从网页抓取数据,这网页是自由免费的完全没限制 ...

一般免费次数足够我们用了。
只要不把key泄露出去。

非要爬页面,那就收得快一点,不要用readStringUntil什么的。
现在网页都是压缩的,基本连回车都没有。
每次读取1个字符,尽快清空缓存。
回复 支持 反对

使用道具 举报

发表于 2020-3-13 16:47:45 | 显示全部楼层
单片机处理网页,根本不要缓存页面。只要预先储存几个标志字符串,定义几个存数据的变量就行了。

接收整个网页的时候,收一个字节,处理一个字节,与预先储存的标志相比,发现标志字符串,就把后面对应的数据挑出来就行了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-4-28 07:50 , Processed in 0.187201 second(s), 14 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

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