Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. # -*- coding: UTF-8 -*-
  2. # !/usr/bin/python
  3.  
  4.  
  5. # read content from the html file
  6. file = open('/Users/marco/PycharmProjects/StyleReplace/wechat.html' ,'r')
  7. str = file.read()
  8. # replace head 2 label
  9. h2Start = '''<p style="line-height: 25.6px; max-width: 100%; min-height: 1em; white-space: pre-wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="max-width: 100%; color: rgb(41, 148, 128); line-height: 25.6px; box-sizing: border-box !important; word-wrap: break-word !important;"></strong></p>
  10. <p style="max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="max-width: 100%; color: rgb(41, 148, 128); line-height: 25.6px; box-sizing: border-box !important; word-wrap: break-word !important;"><span style="max-width: 100%; font-size: 24px; box-sizing: border-box !important; word-wrap: break-word !important;"> ''';
  11.  
  12. h2End = '''</span></strong></p><h2 style="margin-top: 5px; margin-bottom: 10px; white-space: normal; max-width: 100%; box-sizing: border-box; word-wrap: break-word; font-family: sans-serif; line-height: 8px; color: white; border-left: 15px solid rgb(41, 148, 128); background: rgb(73, 200, 149);">&nbsp; &nbsp;</h2>''';
  13. head2 = str.replace('''<h2>''', h2Start);
  14. head2 = head2.replace('''</h2>''', h2End);
  15.  
  16. # replace head 3 label
  17. h3Start = '''<p style="line-height: 25.6px; max-width: 100%; min-height: 1em; white-space: pre-wrap; color: rgb(62, 62, 62); box-sizing: border-box !important; word-wrap: break-word !important; background-color: rgb(255, 255, 255);">
  18. <span style="margin-left: 10px; max-width: 100%; color: rgb(26, 149, 165); box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;"><span style="max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;"><span style="max-width: 100%; font-size: 24px; box-sizing: border-box !important; word-wrap: break-word !important;">''';
  19.  
  20. h3End = '''</span></span></strong></span>
  21. </p>
  22. <h3 style="margin-top: 5px; margin-bottom: 10px; margin-left: 10px; white-space: normal; max-width: 100%; box-sizing: border-box; word-wrap: break-word; outline: none; font-family: sans-serif; line-height: 5px; color: white; border-left: 35px solid rgb(26, 149, 165); background: rgb(38, 198, 218);">
  23. &nbsp; &nbsp;
  24. </h3>''';
  25. head3 = head2.replace('''<h3>''', h3Start);
  26. head3 = head3.replace('''</h3>''', h3End);
  27.  
  28. # replace p title
  29. pStart = '''<p style="margin: 0em 0.5em; white-space: normal; letter-spacing: 1px; text-align: justify; line-height: 1.5em;">
  30. <span style="font-size: 15px; color: rgb(51, 51, 51);">''';
  31.  
  32. pEnd = '''</span></p>''';
  33.  
  34. varP = head3.replace('''<p>''', pStart);
  35. varP = varP.replace('''</p>''', pEnd);
  36.  
  37. # replace blockQuote
  38. quoteStart = '''<br/><blockquote style="margin: 0px 20px 0px 18px; padding: 0px 0px 0px 10px; max-width: 100%; border-left: 5px solid rgb(38, 198, 218); color: rgb(62, 62, 62); font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255); line-height: 25.6px; box-sizing: border-box !important; word-wrap: break-word !important;">''';
  39.  
  40. quote = varP.replace('''<blockquote>''', quoteStart);
  41. # replace the nextline before p label
  42. quote = quote.replace('''mportant;">\n<br/>''', '''break-word !important;">\n''')
  43.  
  44.  
  45. print(quote);
  46.  
  47. file.close();
  48. print("文件名: ", file.name)
  49. print("是否已关闭 : ", file.closed)
  50. print("访问模式 : ", file.mode)
  51. # print("末尾是否强制加空格 : ", file.softspace)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement