本文整理汇总了Python中node.Node.set_descendants方法的典型用法代码示例。如果您正苦于以下问题:Python Node.set_descendants方法的具体用法?Python Node.set_descendants怎么用?Python Node.set_descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node.Node
的用法示例。
在下文中一共展示了Node.set_descendants方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_descendants_with_simple_html
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import set_descendants [as 别名]
def test_set_descendants_with_simple_html(self):
h1_node = Node('bbbbb<h2>cccc</h2>dddd', 'h1')
h1_node.set_descendants()
self.assertEqual(h1_node.children[0].html_body, 'dddd')
self.assertEqual(h1_node.children[0].heading_type, 'h2')
self.assertEqual(h1_node.children[0].heading_title, 'cccc')
self.assertEqual(len(h1_node.children), 1)
self.naver_hay_fever_page = WebPage('http://matome.naver.jp/topic/1LzuV')
示例2: product_nodes
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import set_descendants [as 别名]
def product_nodes(self):
nodes = []
for i, heading in enumerate(self.headings):
node = Node(self.html_texts_divided_by_heading[i], self.children_heading_type)
node.set_heading_title(heading[4:-5]) # <h2>..</h2>のタグ除去
node.set_descendants()
nodes.append(node)
return nodes
示例3: test_set_descendants_with_h1_h2_h3
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import set_descendants [as 别名]
def test_set_descendants_with_h1_h2_h3(self):
h1_node = Node('a<h2>heading1</h2>b<h3>smallheading1</h3>c<h2>heading2</h2>c<h3>smallheading2</h3>d', 'h1')
h1_node.set_descendants()
self.assertEqual(h1_node.children[0].heading_title, 'heading1')
self.assertEqual(h1_node.children[0].children[0].heading_title, 'smallheading1')
self.assertEqual(h1_node.children[1].heading_title, 'heading2')
self.assertEqual(h1_node.children[1].children[0].heading_title, 'smallheading2')
self.assertEqual(len(h1_node.children), 2)
self.assertEqual(len(h1_node.children[0].children), 1)
self.assertEqual(len(h1_node.children[1].children), 1)
示例4: test_set_descendants_with_h1_and_h2
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import set_descendants [as 别名]
def test_set_descendants_with_h1_and_h2(self):
h1_node = Node('<html>a<h2>heading1</h2>b<h2>heading2</h2>c</html>', 'h1')
h1_node.set_descendants()
self.assertEqual(h1_node.children[0].html_body, 'b')
self.assertEqual(h1_node.children[0].heading_type, 'h2')
self.assertEqual(h1_node.children[0].heading_title, 'heading1')
self.assertEqual(h1_node.children[1].html_body, 'c</html>')
self.assertEqual(h1_node.children[1].heading_type, 'h2')
self.assertEqual(h1_node.children[1].heading_title, 'heading2')
self.assertEqual(len(h1_node.children), 2)
示例5: test_set_descendants_with_h3_h5
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import set_descendants [as 别名]
def test_set_descendants_with_h3_h5(self):
h1_node = Node('<h3>heading3</h3><h5>heading5</h5>', 'h1')
h1_node.set_descendants()
self.assertEqual(h1_node.children[0].heading_title, 'heading3')
self.assertEqual(h1_node.children[0].children[0].heading_title, 'heading5')