我想使用python內聯任意網頁。我已經嘗試了幾個庫,但它們都不適用於「真實」的內容,例如有時需要一個複雜的示例。另外,我希望外部樣式表也被內聯。你有什麼建議嗎?這是目前我的測試代碼:是否有任何良好的python css內聯模塊在野外的HTML?
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()
感謝
你究竟想在這裏做什麼? – 2013-09-27 06:16:46