1 ImportUrllib2 ImportOS3 fromBs4ImportBeautifulSoup4 ImportDifflib5 Import Time6 7 while(1):8 ifOs.path.exists ('D:/new.txt') andOs.path.exists ('D:/old.txt'):9Os.remove ('D:/old.txt')Ten ifOs.path.exists ('D:/new.txt'): OneOs.rename ('D:/new.txt','D:/old.txt') AURL ='http://www.zhenxin520.com/trends.asp?id=95' -Response =urllib.urlopen (URL) -Soup =BeautifulSoup (response) theText = Soup.find_all ("TD", attrs={"class":"Text3"}) -F1=open ('D:/new.txt','w+') - f1.write (str (text)) - f1.close () + if notOs.path.exists ('D:/old.txt'): - Continue +F1=open ('D:/new.txt','R') AF2=open ('D:/old.txt','R') atF3=open ('D:/diff.txt','w+') -D=Difflib. Differ () -f1_lines=F1.readlines () -f2_lines=F2.readlines () -diff=list (D.compare (f1_lines,f2_lines)) -Diff2=list (D.compare (f2_lines,f1_lines)) ini =-1 - forLineinchdiff: toI+=1 +Line2 =Diff2[i] - ifline[0]=='-': the Try: *Start = Line.index ('D') $Start2 = Line2.index ('D')Panax NotoginsengSUBSTR =Line[start:] -SUBSTR2 =Line2[start2:] theRMSTR = ['<span>','</span>','<br/>','</p>'] + forJinchRmstr: Asubstr = Substr.replace (J,"') theSUBSTR2 = Substr2.replace (J,"') +F3.write ('New---'+substr+'\nold---'+substr2+'\ n') - except: $ Continue $ f3.close () - f2.close () - f1.close () theTime.sleep (600)
Differ.txt Output Results:
New---D012 red: male l*7 xl*3 xxl*22 female m*2 child 4*7
Old ---D012 red: male l*7 xl*4 xxl*22 female S M L child 4*9
How to monitor inventory movements in real time