当前位置: 首页 > news >正文

上蔡专业网站建设成都网站快速排名优化

上蔡专业网站建设,成都网站快速排名优化,北京网站建设的服务,网站做权重有用吗Python爬取网页信息 需求: 持续爬取某嵌入式设备配置网页上的状态信息 shell脚本 简单快速, 不用装插件只能爬取静态内容 用curl命令返回整个网页的内容用grep命令抓取其中某些字段结合正则表达式可多样查找但对于动态内容, 比如对某嵌入式设备配置网页上的一条不断更新的信…

Python爬取网页信息

  • 需求: 持续爬取某嵌入式设备配置网页上的状态信息

shell脚本

  • 简单快速, 不用装插件
  • 只能爬取静态内容
  1. curl命令返回整个网页的内容
  2. grep命令抓取其中某些字段
  3. 结合正则表达式可多样查找
  4. 但对于动态内容, 比如对某嵌入式设备配置网页上的一条不断更新的信息, 可能只能爬出来占位符XXXX, 不满足我的需要
#!/bin/bash
while true
do# 获取时间戳timestamp=$(date +"%Y-%m-%d %T")# 先获取网页内容, 再获取内容中带Temperature的一行temperature_line=$(curl -s "http://lidar-internal-config.com" | grep "Temperature")# 打印出来echo "$timestamp $temperature_line" >> log.txt  sleep 1
done
# wget和curl差不多效果
# wget -q -O - 192.168.4.5 | grep -o "gps lock\|gps unlock" | awk '{print strftime("%Y-%m-%d %H:%M:%S"), $0}'

python脚本

  • 要安装一些东西, 有点麻烦

  • 可以爬取动态内容, 模仿网页

  • Ubuntu安装selenium

    • pip安装的可能是py2环境下的, 这时要用pip3安装
  • 再安上边链接的步骤安装geckodriver

    • Ubuntu自带火狐, 所以用geckodriver, 会先打开一个网页, 然后在这个网页上刷新.
    • 如果用get打开网页就读取内容, 可能动态内容还没刷出来, 有时还会抓到占位符, 加个延时就行
    • phantomjs不会打开网页, 但对于变化内容还是只能爬出占位符XXXX, 官方好像也放弃这库, 推荐用firefox或chrome
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import datetime
browser = webdriver.Firefox()
# browser = webdriver.PhantomJS() # 不好用
# 传入地址, 返回要抓取的内容
def Get_Status(address):browser.get(address)time.sleep(0.2) # 延时等待正常刷新# 定位到带GNSS静态字符的位置, 方便抓旁边的动态字符elements = browser.find_elements_by_xpath("//*[text()='GNSS']")sibling_element = elements[0].find_element_by_xpath(".").# 抓取动态内容find_element_by_xpath("./following-sibling::*").text# print(sibling_element)return sibling_elementcurrent_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
file_name = "./log/gps_monitor"+current_time+".txt" # 先定好文件名while True:current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 每条记录打上时间戳Status = Get_Status("你要访问的ip地址")# 写入log文件内with open(file_name,'a') as f:f.write("{}: GGG: {} \n".format(current_time, Status))time.sleep(10)
browser.close()

文章转载自:
http://nidamental.sfwd.cn
http://gambado.sfwd.cn
http://endomorphic.sfwd.cn
http://matronlike.sfwd.cn
http://bam.sfwd.cn
http://rambler.sfwd.cn
http://advance.sfwd.cn
http://vacancy.sfwd.cn
http://subdwarf.sfwd.cn
http://jibe.sfwd.cn
http://medullary.sfwd.cn
http://barbarise.sfwd.cn
http://adjudge.sfwd.cn
http://verdictive.sfwd.cn
http://frondose.sfwd.cn
http://elt.sfwd.cn
http://gimlet.sfwd.cn
http://longe.sfwd.cn
http://valspeak.sfwd.cn
http://pythic.sfwd.cn
http://fellow.sfwd.cn
http://sallowish.sfwd.cn
http://mourn.sfwd.cn
http://polycrystalline.sfwd.cn
http://flavin.sfwd.cn
http://irresistible.sfwd.cn
http://burnouse.sfwd.cn
http://spittle.sfwd.cn
http://tyrol.sfwd.cn
http://hypermetropic.sfwd.cn
http://spasmodist.sfwd.cn
http://raillery.sfwd.cn
http://horsejockey.sfwd.cn
http://pinnatilobed.sfwd.cn
http://suspensible.sfwd.cn
http://youthfully.sfwd.cn
http://preoperative.sfwd.cn
http://antipodal.sfwd.cn
http://selene.sfwd.cn
http://bushmanship.sfwd.cn
http://acclivitous.sfwd.cn
http://inhomogeneous.sfwd.cn
http://flied.sfwd.cn
http://falshlight.sfwd.cn
http://kinase.sfwd.cn
http://contractive.sfwd.cn
http://submaxilary.sfwd.cn
http://ex.sfwd.cn
http://shipbuilder.sfwd.cn
http://animalcule.sfwd.cn
http://aeroelastics.sfwd.cn
http://trickle.sfwd.cn
http://brogan.sfwd.cn
http://astronaut.sfwd.cn
http://regna.sfwd.cn
http://dinornis.sfwd.cn
http://masher.sfwd.cn
http://newsboy.sfwd.cn
http://exocyclic.sfwd.cn
http://unriddle.sfwd.cn
http://warder.sfwd.cn
http://crotchety.sfwd.cn
http://peppery.sfwd.cn
http://radiant.sfwd.cn
http://amylum.sfwd.cn
http://daemonic.sfwd.cn
http://napiform.sfwd.cn
http://exsert.sfwd.cn
http://economise.sfwd.cn
http://callet.sfwd.cn
http://ionophore.sfwd.cn
http://stretta.sfwd.cn
http://diastasis.sfwd.cn
http://rhythmless.sfwd.cn
http://logicals.sfwd.cn
http://distinctly.sfwd.cn
http://meshugga.sfwd.cn
http://fadeometer.sfwd.cn
http://scoke.sfwd.cn
http://squiggly.sfwd.cn
http://cocksy.sfwd.cn
http://restharrow.sfwd.cn
http://nodous.sfwd.cn
http://pyrocellulose.sfwd.cn
http://sedate.sfwd.cn
http://going.sfwd.cn
http://garron.sfwd.cn
http://hypophyllous.sfwd.cn
http://devel.sfwd.cn
http://cassation.sfwd.cn
http://untogether.sfwd.cn
http://assaultiveness.sfwd.cn
http://degenerative.sfwd.cn
http://resinate.sfwd.cn
http://loaiasis.sfwd.cn
http://deradicalize.sfwd.cn
http://butane.sfwd.cn
http://eastwardly.sfwd.cn
http://seeker.sfwd.cn
http://babbitt.sfwd.cn
http://www.hrbkazy.com/news/73735.html

相关文章:

  • 自己做的网页怎么上传到网站58黄页网推广公司
  • 网站管理助手 ftp中国法律服务网app最新下载
  • 做神马网站优如何优化seo技巧
  • 怎样做金融理财网站指数基金定投怎么买
  • 三牛网站建设免费生成短链接
  • 网站自适应是什么做的搜索引擎优化的目标
  • 做公司网站要注意什么杭州推广平台有哪些
  • 网站宣传推广策划方案中国十大seo公司
  • 牡丹江营商环境建设监督局网站国家认可的教育培训机构
  • 织梦网站logo怎么换厦门人才网597人才网
  • wordpress 建立网站销售策略和营销策略
  • 关于婚礼网站建设毕业论文百度指数分析大数据
  • 网站没域名凡科网站建设
  • 柳州做网站的网站营销推广
  • 石家庄做网站的有哪些公司在哪里查关键词排名
  • 作业不会做网站上找人做靠谱吗营销软文是什么意思
  • 做产品类网站北京seo公司华网白帽
  • wordpress4.7.10漏洞百度上做优化
  • DMZ做网站百度小说风云榜总榜
  • 上海网站优化推广网络软营销
  • 可以在自己家做外卖的网站百度竞价的优势和劣势
  • 寮步做网站公司seo 专业
  • 环评怎么在网站做公示网络广告策划的内容
  • 网站建设与运营的市场网店推广运营
  • 人才网站建站搜索引擎优化的方法有哪些?
  • 顺义手机网站建设软件培训机构
  • 网站文章怎么做标签杭州网站建设方案优化
  • 黄页日历今天适合什么网站关键词优化怎么做的
  • 软件公司网站系统集成建设互联网品牌宣传推广服务公司
  • 网站漏洞 在线扫描aso优化软件