我想使用 python 内联任意网页。我已经尝试了几个库,但它们都不能很好地处理“真实”内容,例如 nytimes 举一个复杂的例子。另外,我也希望内联外部样式表。你有什么建议吗?这是我目前的测试代码:
import requests
import codecs
from html5tidy import tidy
url = "http://www.nytimes.com/"
r = requests.get(url)
src = tidy(r.text)
from pypremailer import Premailer
p = Premailer(src)
output = p.premail()
f = open("/tmp/pypremailer.html", "w")
f.write(output)
f.close()
from premailer import transform
output = transform(src)
f = open("/tmp/premailer.html", "w")
f.write(output)
f.close()
import pynliner
output = pynliner.fromString(src)
f = open("/tmp/pynliner.html", "w")
f.write(output)
f.close()
from inlinestyler.utils import inline_css
output = inline_css(src)
f = open("/tmp/inlinestyler.html", "w")
f.write(output)
f.close()
谢谢