我的脚本的这一部分旨在将网站页面与上次运行的文本文档进行比较。 我遇到的问题是它只返回1行已更改并忽略了之后的所有内容?
我需要做些什么来改变所有内容?
def moo(DocIn, DocOut, WebAddy, Pub, Pub2, PDF):
os.rename(DocIn, DocOut) # Renames the old compare document to 2
file(DocIn, "wb").write(urllib2.urlopen(WebAddy).read()) # Creates a new document to compare from
hosts0 = open(DocIn,"rb")
hosts1 = open(DocOut,"rb")
lines1 = hosts0.readlines()
for i, lines2 in enumerate(hosts1):
if lines2 != lines1[i]:
chgdoc(DocOut, lines2)
print "line ", i, " in hosts1 is different \n"
print lines2
def chgdoc(DocOut, lines2):
fileName, fileExtension = os.path.splitext(DocOut)
file = open(fileName + '_3' + fileExtension, "a")
file.write(lines2)
file.close()