python監控系統,python監控網頁內容變化_使用Python監控文件內容變化代碼實例

 2023-10-06 阅读 31 评论 0

摘要:利用seek監控文件內容,并打印出變化內容:#/usr/bin/env python#-*- coding=utf-8 -*-pos = 0python監控系統、while True:con = open("a.txt")if pos != 0:con.seek(pos,0)while True:網頁內容變動監控、line = con.readline()if l

利用seek監控文件內容,并打印出變化內容:

#/usr/bin/env python

#-*- coding=utf-8 -*-

pos = 0

python監控系統、while True:

con = open("a.txt")

if pos != 0:

con.seek(pos,0)

while True:

網頁內容變動監控、line = con.readline()

if line.strip():

print line.strip()

pos = pos + len(line)

if not line.strip():

web監控軟件?break

con.close()

利用工具pyinotify監控文件內容變化,當文件逐漸變大時,可輕松完成任務:

#!/usr/bin/env python

#-*- coding=utf-8 -*-

python簡單代碼、import os

import datetime

import pyinotify

import logging

pos = 0

Python代碼。def printlog():

global pos

try:

fd = open("log/a.txt")

if pos != 0:

python爬蟲教程、fd.seek(pos,0)

while True:

line = fd.readline()

if line.strip():

print line.strip()

python怎么用?pos = pos + len(line)

if not line.strip():

break

fd.close()

except Exception,e:

python3,print str(e)

class MyEventHandler(pyinotify.ProcessEvent):

def process_IN_MODIFY(self,event):

try:

printlog()

python獲取網頁數據,except Exception,e:

print str(e)

def main():

printlog()

wm = pyinotify.WatchManager()

python如何獲取網頁信息。wm.add_watch("log/a.txt",pyinotify.ALL_EVENTS,rec=True)

eh = MyEventHandler()

notifier = pyinotify.Notifier(wm,eh)

notifier.loop()

if __name__ == "__main__":

python抓取網頁內容并保存,main()

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/122650.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息