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


Python TemplateMaker.selected_data方法代码示例

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


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

示例1: do_annotate

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import selected_data [as 别名]
    def do_annotate(self, line):
        """annotate <template_id> <data> [-n number] [-f field]- add or test annotation (aliases: a, t)

        Add a new annotation (if -f is passed) or test what would be annotated
        otherwise
        """
        if line.find(' ') < 0:
            print("You must provide a valid template identifier (check output of ls_templates)")
            print(IblTool.do_annotate.__doc__)
            return
        template_id, criteria = line.split(' ', 1)
        t = self._load_template(template_id)
        if not t:
            return
        criteria = self._parse_criteria(criteria)
        tm = TemplateMaker(t)
        selection = apply_criteria(criteria, tm)
        if criteria.field:
            for index in selection:
                index = selection[0]
                tm.annotate_fragment(index, criteria.field)
                self._save_template(template_id, tm.get_template())
                print("[new] (%s) %r" % (criteria.field,
                    remove_annotation(tm.selected_data(index))))
        else:
            for n, i in enumerate(selection):
                print("[%d] %r" % (n, remove_annotation(tm.selected_data(i))))
开发者ID:CodeOps,项目名称:scrapely,代码行数:29,代码来源:tool.py

示例2: test_selected_data

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import selected_data [as 别名]
 def test_selected_data(self):
     tm = TemplateMaker(self.PAGE)
     indexes = tm.select(best_match('text to annotate'))
     data = [tm.selected_data(i) for i in indexes]
     self.assertEqual(data, \
         [u'<p>Some text to annotate here</p>', \
         u'<p>Another text to annotate there</p>'])
开发者ID:scrapy,项目名称:scrapely,代码行数:9,代码来源:test_template.py

示例3: do_al

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import selected_data [as 别名]
 def do_al(self, template_id):
     """al <template> - list annotations"""
     if assert_or_print(template_id, "missing template id"):
         return
     t = self._load_template(template_id)
     tm = TemplateMaker(t)
     for n, (a, i) in enumerate(tm.annotations()):
         print "[%s-%d] (%s) %r" % (template_id, n, a['annotations']['content'], 
             remove_annotation(tm.selected_data(i)))
开发者ID:esimionato,项目名称:scrapely,代码行数:11,代码来源:tool.py

示例4: do_t

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import selected_data [as 别名]
 def do_t(self, line):
     """ts <template> <text> - test selection text"""
     template_id, criteria = line.split(' ', 1)
     t = self._load_template(template_id)
     criteria = parse_criteria(criteria)
     tm = TemplateMaker(t)
     selection = apply_criteria(criteria, tm)
     for n, i in enumerate(selection):
         print "[%d] %r" % (n, remove_annotation(tm.selected_data(i)))
开发者ID:esimionato,项目名称:scrapely,代码行数:11,代码来源:tool.py

示例5: do_a

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import selected_data [as 别名]
 def do_a(self, line):
     """a <template> <data> [-n number] [-f field]- add or test annotation
     
     Add a new annotation (if -f is passed) or test what would be annotated
     otherwise
     """
     template_id, criteria = line.split(' ', 1)
     t = self._load_template(template_id)
     criteria = parse_criteria(criteria)
     tm = TemplateMaker(t)
     selection = apply_criteria(criteria, tm)
     if criteria.field:
         for index in selection:
             index = selection[0]
             tm.annotate_fragment(index, criteria.field)
             self._save_template(template_id, tm.get_template())
             print "[new] (%s) %r" % (criteria.field,
                 remove_annotation(tm.selected_data(index)))
     else:
         for n, i in enumerate(selection):
             print "[%d] %r" % (n, remove_annotation(tm.selected_data(i)))
开发者ID:esimionato,项目名称:scrapely,代码行数:23,代码来源:tool.py

示例6: test_selected_data

# 需要导入模块: from scrapely.template import TemplateMaker [as 别名]
# 或者: from scrapely.template.TemplateMaker import selected_data [as 别名]
 def test_selected_data(self):
     tm = TemplateMaker(self.PAGE)
     indexes = tm.select(best_match("text to annotate"))
     data = [tm.selected_data(i) for i in indexes]
     self.assertEqual(data, [u"<p>Some text to annotate here</p>", u"<p>Another text to annotate there</p>"])
开发者ID:netconstructor,项目名称:scrapely,代码行数:7,代码来源:test_template.py


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