【发布时间】:2014-09-19 22:40:48
【问题描述】:
我正在尝试让我的 Python 模板引擎向后工作。即给定模板和数据不仅生成文档,还提取给定模板和文档的数据。
给定页面
<ul>
<li><a href="/polls/456/">What is your name, stranger?</a></li>
</ul>
和模板
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
它将返回一个包含该项目的latest_question_list。
您使用什么工具来执行此操作?它不必支持 Django 模板,其他模板引擎也可以。
【问题讨论】:
-
非常有趣,这需要大量的计划。您将必须确保每个页面的数据结构相同,或者您有一些配置文件来了解页面上的数据类型以及您获得的数据到底是什么。跨度>
-
textfsm 半结构化文本解析器code.google.com/p/textfsm/wiki/TextFSMHowto
标签: python parsing templates django-templates template-engine