下面代码是用coolformat处理的 --- 拔剑
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
SAPERATOR= "-----" file_name = "e:\\图像与机器学习.txt" file_name1 = "e:\\图像与机器学习.html" file = open (file_name, "r" ) lines= file . readlines () line1={} # in HTML means blankspace pattern=re. compile (HTTP_PROTOCOL); pattern_saperator=re. compile (SAPERATOR); line_text_with_URL= "" for line in lines: m=pattern.search(line) print line,m if m is not None : line_text_with_URL += ahref_text % (line. strip (),line) #remove useless blankspace in orignal URL string else : m = pattern_saperator.match(line) if m is not None : line_text_with_URL += plain_text2 % "" # replace "------" with HTML saperator line_text_with_URL += ' ' ; # add return else : line_text_with_URL += plain_text % line. strip () #print line_text_with_URL html = HTML_TEXT % line_text_with_URL file2 = open (file_name1, "w" ); file2. write (html) file2. close (); |