html email and python - a journey dave cranwell
Post on 31-Dec-2015
233 Views
Preview:
TRANSCRIPT
ClientsDesktop Web
Outlook (03,07)Windows MailMac MailEntourage (04,08)ThunderbirdAOL (9,10,Mac)NotesEudora
Yahoo (old, new)Gmail (old, new)Windows Live mailHotmailAOL WebMobileMe
Dave Cranwell. HTML email and Python – a journey
Dave Cranwell. HTML email and Python – a journey
ClientsDesktop Web
Outlook (03,07,10)Windows MailMac MailEntourage (04,08)ThunderbirdAOL (9,10,Mac)NotesEudora
Yahoo (old, new)Gmail (old, new)Windows Live mailHotmailAOL WebMobileMe
Booo
Hiss!
No <style> No <link>
complete crap
Libraries
• Beautiful Soup– Element Soup
• Element Tree• lXML• Minidom• PyQuery
Dave Cranwell. HTML email and Python – a journey
• CSS Utils
Python Package Index: http://pypi.python.org
Libraries
• Beautiful Soup– Element Soup
• Element Tree• lXML• Minidom• PyQuery
Dave Cranwell. HTML email and Python – a journey
• CSS Utils
lXML
• Pythonic binding of libxml2 (C)• up to 20 X faster than Beautiful Soup at
parsing *• Includes CSSSelect, which converts a CSS 2.1
selector into an Xpath
* http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/
Dave Cranwell. HTML email and Python – a journey
Whats happening?• lXML parses HTML and converts to an eTree• CSSUtils parses CSS rules into objects• Loop over CSS rules converting each to XPath
with CSSSelect• Create CSSStyleDeclaration for each element
affected by a CSS rule– Contains details of the tag as well as the combined
styles applied• Loop over eTree and serialised matching
CSSStyleDeclarations into the “style” attribute.
Dave Cranwell. HTML email and Python – a journey
No Google App engine, sadly
• No C libs x• Pure Python only x– (and java)
• Piss easy to setup • Bloody cool
Dave Cranwell. HTML email and Python – a journey
top related