利用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()
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态