import sys with open('tmp_home_fixed2.html', 'r', encoding='utf-8') as f: content = f.read() new_css = """ body.home .wp-site-blocks, body.home main, body.home .entry-content, body.home .wp-block-post-content, body.home .type-page { padding-top: 0 !important; margin-top: 0 !important; } body.home .kmc-landing { margin-top: 0 !important; padding-top: 0 !important; } """ content = content.replace("body.home main { margin-top: 0 !important; padding-top: 0 !important; }", new_css) with open('tmp_home_final.html', 'w', encoding='utf-8') as f: f.write(content)