Рішення:
{% if news_date.grouper %} {% if forloop.parentloop.first and forloop.first %} {{ news_date.grouper }} {% else %} {{ news_date.grouper }} {% endif %} {% else %} Сьогодні {% endif %}
{% if news_date.grouper %} {% if forloop.parentloop.first and forloop.first %} {{ news_date.grouper }} {% else %} {{ news_date.grouper }} {% endif %} {% else %} Сьогодні {% endif %}
sudo apt-get update && sudo apt-get upgrade sudo apt-get install build-essential checkinstall libncurses5-dev curl curl --o mysql-4.1.24.tar.gz http://mirror.provenscaling.com/mysql/community/source/4.1/mysql-4.1.24.tar.gz sudo tar -xvzf mysql-4.1.24.tar.gz --directory=/usr/local/src cd /usr/local/src/mysql-4.1.24/ sudo groupadd mysql sudo useradd -g mysql mysql sudo apt-get install sudo ./configure --prefix=/usr/local/mysql sudo make sudo mkdir /usr/local/mysql sudo mkdir /usr/local/mysql/include sudo mkdir /usr/local/mysql/include/mysql sudo mkdir /usr/local/mysql/lib sudo mkdir /usr/local/mysql/lib/mysql sudo mkdir /usr/local/mysql/share sudo mkdir /usr/local/mysql/man sudo mkdir /usr/local/mysql/mysql-test sudo checkinstall y mysql-server 4.1.24 dpkg -l | grep -i mysql sudo cp support-files/my-medium.cnf /etc/my.cnf cd /usr/local/mysql/ pwd bin/mysql_install_db --user=mysql sudo chown -R root . sudo chown -R mysql var sudo chgrp -R mysql . bin/mysql --version bin/mysql_install_db --user=mysql sudo bin/mysqld_safe user=mysql &
from lxml import etree from lxml import html as lxml_html from lxml.html import clean, fromstring, tostring, _transform_result, copy remove_attrs = ['class', 'width', 'cellspacing', 'cellpadding', 'border'] remove_tags = ['a', 'p', 'span', 'div', 'strong'] nonempty_tags = [] class MyCleaner(clean.Cleaner): def clean_html(self, html, parser=None): result_type = type(html) if isinstance(html, basestring): doc = fromstring(html, parser=parser) else: doc = copy.deepcopy(html) self(doc) return _transform_result(result_type, doc) cleaner = MyCleaner(remove_tags=remove_tags, page_structure=False) def squeaky_clean(html): parser = lxml_html.HTMLParser(encoding='utf-8') clean_html = cleaner.clean_html(html, parser) root = fromstring(clean_html) context = etree.iterwalk(root) for action, elem in context: clean_text = elem.text and elem.text.strip(' \t\r\n') if elem.tag in nonempty_tags and \ not (len(elem) or clean_text): elem.getparent().remove(elem) continue elem.text = clean_text for badattr in remove_attrs: if elem.attrib.has_key(badattr): del elem.attrib[badattr] return tostring(root, encoding='ISO-8859-1') html = squeaky_clean(DATA) print htmlІ на виході маємо результат: