赞
踩
CSDN 和百问网一起发
开发板直接接在路由器或者交换机下,确保这个交换机或者路由器能连接到需要下载的网络,本节会以下载百度的网页作为demo
所以需要 开发板能连接到外网。这一点很重要。
这一步基本看一下网口灯就行了,正常的连接状态网口灯应该是亮起的。
建议使用dhcp 的方式给开发板获得固定的IP ,笔者在野火的板子上进行测试的时候发现存在使用固定IP 的情况下缺少DNS 配置的问题。(笔者是自行写了配置脚本,开发板 可以运行脚本挂载 nfs 服务) 在百问网的板子上测试的时候发现使用udhcpc 获得动态IP的过程中直接附带了路由器的DNS 服务器信息。
使用固定IP 导致的缺少DNS 也可以通过修改配置文件解决 (执行以下语句 其中的223.5.5.5 为阿里云的DNS 服务)
echo "nameserver 223.5.5.5" >> /etc/resolv.conf
默认板子重启之后的配置文件 /etc/resolv.conf 如下 (貌似也能ping到百度)
[root@imx6ull:~]# cat /etc/resolv.conf # 板子上电之后的DNS配置信息 # Generated by Connection Manager nameserver ::1 nameserver 127.0.0.1 [root@imx6ull:~]# udhcpc # 获取动态IP udhcpc: started, v1.29.3 udhcpc: sending discover udhcpc: sending select for 192.168.1.110 udhcpc: lease of 192.168.1.110 obtained, lease time 7200 deleting routers adding dns 202.96.134.33 adding dns 202.96.128.166 [root@imx6ull:~]# cat /etc/resolv.conf #再次查看DNS 信息 # Generated by Connection Manager nameserver ::1 nameserver 127.0.0.1 nameserver 202.96.134.33 # eth0 nameserver 202.96.128.166 # eth0 [root@imx6ull:~]#
综合起来就是 : 最好就是 开发板上电之后 运行 udhcpc 获得一个路由器分配的动态IP 。并且要能成功的ping通外网
[root@imx6ull:~]# ping www.baidu.com
PING www.baidu.com (14.215.177.38): 56 data bytes
64 bytes from 14.215.177.38: seq=0 ttl=56 time=7.638 ms
64 bytes from 14.215.177.38: seq=1 ttl=56 time=7.580 ms
[root@imx6ull:~]# wget www.baidu.com --2021-01-31 15:17:30-- http://www.baidu.com/ Resolving www.baidu.com... 14.215.177.39, 14.215.177.38 Connecting to www.baidu.com|14.215.177.39|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2381 (2.3K) [text/html] Saving to: 'index.html' index.html 100%[===================>] 2.33K --.-KB/s in 0s 2021-01-31 15:17:30 (17.0 MB/s) - 'index.html' saved [2381/2381] [root@imx6ull:~]# cat index.html <!DOCTYPE html> <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html> [root@imx6ull:~]#
如上述的片段显示的,通过wget 工具我们成功的获取了 百度的首页。
接下来获取一个图片 分析上面的html语言不难找到百度的首页图片,直接下载下来这个资源。
[root@imx6ull:~]# wget www.baidu.com/img/bd_logo1.png
--2021-01-31 15:19:46-- http://www.baidu.com/img/bd_logo1.png
Resolving www.baidu.com... 14.215.177.39, 14.215.177.38
Connecting to www.baidu.com|14.215.177.39|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7877 (7.7K) [image/png]
Saving to: 'bd_logo1.png'
bd_logo1.png 100%[===================>] 7.69K --.-KB/s in 0.004s
2021-01-31 15:19:46 (1.99 MB/s) - 'bd_logo1.png' saved [7877/7877]
[root@imx6ull:~]# ls
bd_logo1.png index.html
如果想要将所有的资源都下载下来 需要加入 -p 参数
[root@imx6ull:~/temp]# wget -p www.baidu.com --2021-01-31 15:23:25-- http://www.baidu.com/ Resolving www.baidu.com... 14.215.177.39, 14.215.177.38 Connecting to www.baidu.com|14.215.177.39|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2381 (2.3K) [text/html] Saving to: 'www.baidu.com/index.html' www.baidu.com/index 100%[===================>] 2.33K --.-KB/s in 0s 2021-01-31 15:23:25 (18.1 MB/s) - 'www.baidu.com/index.html' saved [2381/2381] Loading robots.txt; please ignore errors. --2021-01-31 15:23:25-- http://www.baidu.com/robots.txt Reusing existing connection to www.baidu.com:80. HTTP request sent, awaiting response... 200 OK Length: 2814 (2.7K) [text/plain] Saving to: 'www.baidu.com/robots.txt' www.baidu.com/robot 100%[===================>] 2.75K --.-KB/s in 0s 2021-01-31 15:23:25 (26.5 MB/s) - 'www.baidu.com/robots.txt' saved [2814/2814] FINISHED --2021-01-31 15:23:25-- Total wall clock time: 0.06s Downloaded: 2 files, 5.1K in 0s (21.8 MB/s)
通过上述的代码 我们发现并没有把所有的文件都拿下来,可能是因为百度的反爬虫机制。不懂,估计也用不到
这个需要提前知道服务器资源的位置
例如下载
wget http://mirrors.aliyun.com/ubuntu/project/ubuntu-archive-keyring.gpg.sig
wget https://gitee.com/weidongshan/openharmony_for_imx6ull.git --no-check-certificate # git
wget https://atta.szlcsc.com/upload/public/pdf/source/20190802/C375844_D1F11326408C489F34467373E22B71B9.pdf #立创商城的datesheet
wget http://wechatapppro-1252524126.file.myqcloud.com/appTVs2sJfo3933/image/3c196c4ca0f94877e848239b68e0e948.png # 百问网的图标
wget https://cloud.firebbs.cn/portal/202005/18/173859n5cfr16h1u1ccczf.jpg # 野火BBS 的封面
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。