with open('/www/wwwroot/gaokao/index.html', 'r') as f: content = f.read() # Find the first tag last_style_end = content.rindex('') + len('') before = content[:first_style] after = content[last_style_end:] # Read the new CSS from a separate file (will write separately) new_html = before + '' + after with open('/www/wwwroot/gaokao/index.html', 'w') as f: f.write(new_html) print('Marked')