lxml es más rápido que BeautifulSoup (creo) y tiene mucho mejor funcionalidad, sin dejar de ser relativamente fácil de usar. Ejemplo:
52> from urllib import urlopen
53> from lxml import etree
54> f = urlopen("http://www.google.com").read()
55> tree = etree.HTML(f)
61> m = tree.xpath("//meta")
62> for i in m:
..> print etree.tostring(i)
..>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-2"/>
Edición: otro ejemplo.
75> f = urlopen("http://www.w3schools.com/XPath/xpath_syntax.asp").read()
76> tree = etree.HTML(f)
85> tree.xpath("//meta[@name='Keywords']")[0].get("content")
85> "xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,b
eginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading
style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide"
BTW: XPath es la pena conocer.
Otra edición:
Como alternativa, sólo puede utilizar expresiones regulares:
87> f = urlopen("http://www.w3schools.com/XPath/xpath_syntax.asp").read()
88> import re
101> re.search("<meta name=\"Keywords\".*?content=\"([^\"]*)\"", f).group(1)
101>"xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql, ...etc...
... pero me resulta menos legible y más propenso a errores (pero implica únicamente módulo estándar y todavía cabe en una línea).
Asegúrese de utilizar el almacenamiento en caché de los contenidos siempre que sea posible https://developer.yahoo.com/python/python-caching.html – fedmich