120 likes | 199 Views
Explore the seamless integration of HTML email and Python, enhancing efficiency and creativity. Discover libraries such as Beautiful Soup, lxml, and more. Dive into Pythonic web parsing techniques for faster results.
E N D
HTML emailand Python- a journey Dave Cranwell.
Clients Dave Cranwell. HTML email and Python – a journey
CampaignMonitor.com/css Dave Cranwell. HTML email and Python – a journey
Clients Booo No <style> No <link> Hiss! complete crap Dave Cranwell. HTML email and Python – a journey
Python to the rescue! LULZ Dave Cranwell. HTML email and Python – a journey
Libraries Python Package Index: http://pypi.python.org • Beautiful Soup • Element Soup • Element Tree • lXML • Minidom • PyQuery • CSS Utils Dave Cranwell. HTML email and Python – a journey
Libraries • Beautiful Soup • Element Soup • Element Tree • lXML • Minidom • PyQuery • CSS Utils Dave Cranwell. HTML email and Python – a journey
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
Introducing... 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 libsx • Pure Python only x • (and java) • Piss easy to setup P • Bloody cool P Dave Cranwell. HTML email and Python – a journey
FIN Dave Cranwell. david@torchbox.com