当前位置: 首页>>代码示例>>Python>>正文


Python TemplateMaker.annotate方法代码示例

本文整理汇总了Python中scrapely.template.TemplateMaker.annotate方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateMaker.annotate方法的具体用法?Python TemplateMaker.annotate怎么用?Python TemplateMaker.annotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scrapely.template.TemplateMaker的用法示例。


在下文中一共展示了TemplateMaker.annotate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_annotations

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def test_annotations(self):
     tm = TemplateMaker(self.PAGE)
     tm.annotate('field1', best_match('text to annotate'), best_match=False)
     annotations = [x[0] for x in tm.annotations()]
     self.assertEqual(annotations,
         [{u'annotations': {u'content': u'field1'}},
          {u'annotations': {u'content': u'field1'}}])
开发者ID:scrapy,项目名称:scrapely,代码行数:9,代码来源:test_template.py

示例2: test_annotations

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def test_annotations(self):
     tm = TemplateMaker(self.PAGE)
     tm.annotate("field1", best_match("text to annotate"), best_match=False)
     annotations = [x[0] for x in tm.annotations()]
     self.assertEqual(
         annotations, [{u"annotations": {u"content": u"field1"}}, {u"annotations": {u"content": u"field1"}}]
     )
开发者ID:netconstructor,项目名称:scrapely,代码行数:9,代码来源:test_template.py

示例3: test_annotate_ignore_unpaired

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def test_annotate_ignore_unpaired(self):
     tm = TemplateMaker(self.PAGE)
     tm.annotate('field1', best_match("and that's"), best_match=False)
     tpl = tm.get_template()
     ex = InstanceBasedLearningExtractor([(tpl, None)])
     self.assertEqual(ex.extract(self.PAGE)[0],
         [{u'field1': [u"More text with unpaired tag <img />and that's it"]}])
开发者ID:scrapy,项目名称:scrapely,代码行数:9,代码来源:test_template.py

示例4: test_annotate_multiple

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def test_annotate_multiple(self):
     tm = TemplateMaker(self.PAGE)
     tm.annotate('field1', best_match('text to annotate'), best_match=False)
     tpl = tm.get_template()
     ex = InstanceBasedLearningExtractor([(tpl, None)])
     self.assertEqual(ex.extract(self.PAGE)[0],
         [{u'field1': [u'Some text to annotate here', u'Another text to annotate there']}])
开发者ID:scrapy,项目名称:scrapely,代码行数:9,代码来源:test_template.py

示例5: test_annotate_multiple

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def test_annotate_multiple(self):
     tm = TemplateMaker(self.PAGE)
     tm.annotate("field1", best_match("text to annotate"), best_match=False)
     tpl = tm.get_template()
     ex = InstanceBasedLearningExtractor([tpl])
     self.assertEqual(
         ex.extract(self.PAGE)[0], [{u"field1": [u"Some text to annotate here", u"Another text to annotate there"]}]
     )
开发者ID:netconstructor,项目名称:scrapely,代码行数:10,代码来源:test_template.py

示例6: train_from_htmlpage

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def train_from_htmlpage(self, htmlpage, data):
     assert data, "Cannot train with empty data"
     tm = TemplateMaker(htmlpage)
     for field, values in data.items():
         if (isinstance(values, (bytes, str)) or
                 not hasattr(values, '__iter__')):
             values = [values]
         for value in values:
             value = str_to_unicode(value, htmlpage.encoding)
             tm.annotate(field, best_match(value))
     self.add_template(tm.get_template())
开发者ID:CodeOps,项目名称:scrapely,代码行数:13,代码来源:__init__.py

示例7: train_from_htmlpage

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def train_from_htmlpage(self, htmlpage, data):
     assert data, "Cannot train with empty data"
     tm = TemplateMaker(htmlpage)
     for field, values in data.items():
         if not hasattr(values, '__iter__'):
             values = [values]
         for value in values:
             if isinstance(value, str):
                 value = value.decode(htmlpage.encoding or 'utf-8')
             tm.annotate(field, best_match(value))
     self.add_template(tm.get_template())
开发者ID:1060460048,项目名称:scrapely,代码行数:13,代码来源:__init__.py

示例8: train

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def train(self, url=None, data=None, html=None, encoding='utf-8'):
     assert data, "Cannot train with empty data"
     page = self._get_page(url, encoding, html)
     tm = TemplateMaker(page)
     for field, values in data.items():
         if not hasattr(values, '__iter__'):
             values = [values]
         for value in values:
             if isinstance(value, str):
                 value = value.decode(encoding)
             tm.annotate(field, best_match(value))
     self.templates.append(tm.get_template())
开发者ID:carriercomm,项目名称:scraperwiki-scraper-vault,代码行数:14,代码来源:scrapely-hack.py

示例9: test_annotate_fragment_already_annotated

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import annotate [as 别名]
 def test_annotate_fragment_already_annotated(self):
     tm = TemplateMaker(self.PAGE)
     tm.annotate("field1", best_match("text to annotate"))
     self.assertRaises(FragmentAlreadyAnnotated, tm.annotate, "field1", best_match("text to annotate"))
开发者ID:netconstructor,项目名称:scrapely,代码行数:6,代码来源:test_template.py


注:本文中的scrapely.template.TemplateMaker.annotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。