Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python/php中的模板提取_Php_Python_Templates_Extract - Fatal编程技术网

python/php中的模板提取

python/php中的模板提取,php,python,templates,extract,Php,Python,Templates,Extract,python或php中是否存在现有的模板提取库?Perl已经实现了,但我在python或php中都找不到类似的实现 在python中,我能找到的唯一相近的东西是TemplateMaker(),但它并不是一个真正的模板提取库。TmeplateMaker似乎可以满足您的需要,至少从它的文档来看是这样的。它不是接收模板作为输入,而是从几个文档推断(“学习”)if。然后,它使用extract方法从使用此模板创建的其他文档中提取数据 示例显示: # Now that we have a template,

python或php中是否存在现有的模板提取库?Perl已经实现了,但我在python或php中都找不到类似的实现


在python中,我能找到的唯一相近的东西是TemplateMaker(),但它并不是一个真正的模板提取库。

TmeplateMaker
似乎可以满足您的需要,至少从它的文档来看是这样的。它不是接收模板作为输入,而是从几个文档推断(“学习”)if。然后,它使用
extract
方法从使用此模板创建的其他文档中提取数据

示例显示:

# Now that we have a template, let's extract some data.
>>> t.extract('<b>red and green</b>')
('red', 'green')
>>> t.extract('<b>django and stephane</b>')
('django', 'stephane')

# The extract() method is very literal. It doesn't magically trim
# whitespace, nor does it have any knowledge of markup languages such as
# HTML.
>>> t.extract('<b>  spacy  and <u>underlined</u></b>')
('  spacy ', '<u>underlined</u>')

# The extract() method will raise the NoMatch exception if the data
# doesn't match the template. In this example, the data doesn't have the
# leading and trailing "<b>" tags.
>>> t.extract('this and that')
Traceback (most recent call last):
...
#现在我们有了一个模板,让我们提取一些数据。
>>>t.提取物(“红色和绿色”)
(‘红色’、‘绿色’)
>>>t.提取物(“django和stephane”)
(“django”、“stephane”)
#extract()方法非常简单。它不会神奇地修剪
#它也不了解标记语言,例如
#HTML。
>>>t.extract('空格和下划线')
(“空格”、“下划线”)
#如果数据丢失,extract()方法将引发NoMatch异常
#与模板不匹配。在本例中,数据没有
#前导和尾随“”标记。
>>>t.extract('这个和那个')
回溯(最近一次呼叫最后一次):
...
因此,为了完成您需要的任务,我认为您应该:

  • 给它一些从你的模板中呈现出来的文档——它从中推断模板不会有问题
  • 使用推断模板从新文档中提取数据

仔细想想,它甚至比Perl的
模板::Extract
更有用,因为它不希望您为它提供一个干净的模板-它自己从示例文本中学习。

下面是TemplateMaker作者Adrian的一个有趣讨论

它看起来很像我所说的包装归纳库


如果您正在寻找其他更具可配置性(较少用于刮削)的内容,请查看lxml.html和BeautifulSoup,以及python。

在深入研究了更多内容后,我找到了一个解决方案,完全符合我的要求。filippo在这篇文章中发布了一系列用于屏幕抓取的python解决方案:其中有一个名为scrapemark()的包


希望这能帮助其他正在寻找相同解决方案的人。

@Kyle:也许你需要重新表述你的问题