Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: UTF-8 -*-
- # !/usr/bin/python
- # read content from the html file
- file = open('/Users/marco/PycharmProjects/StyleReplace/wechat.html' ,'r')
- str = file.read()
- # replace head 2 label
- 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>
- <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;"> ''';
- 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);"> </h2>''';
- head2 = str.replace('''<h2>''', h2Start);
- head2 = head2.replace('''</h2>''', h2End);
- # replace head 3 label
- 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);">
- <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;">''';
- h3End = '''</span></span></strong></span>
- </p>
- <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);">
-
- </h3>''';
- head3 = head2.replace('''<h3>''', h3Start);
- head3 = head3.replace('''</h3>''', h3End);
- # replace p title
- pStart = '''<p style="margin: 0em 0.5em; white-space: normal; letter-spacing: 1px; text-align: justify; line-height: 1.5em;">
- <span style="font-size: 15px; color: rgb(51, 51, 51);">''';
- pEnd = '''</span></p>''';
- varP = head3.replace('''<p>''', pStart);
- varP = varP.replace('''</p>''', pEnd);
- # replace blockQuote
- 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;">''';
- quote = varP.replace('''<blockquote>''', quoteStart);
- # replace the nextline before p label
- quote = quote.replace('''mportant;">\n<br/>''', '''break-word !important;">\n''')
- print(quote);
- file.close();
- print("文件名: ", file.name)
- print("是否已关闭 : ", file.closed)
- print("访问模式 : ", file.mode)
- # print("末尾是否强制加空格 : ", file.softspace)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement