I work in program FreeMind which allows to create trees and import them as HTML files and I need to get every "path" of this tree and put them into list for example to work with each "path" separately after.
For example from this code:
<body>
<p>Example</p>
<ul>
<li>
The First List
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</li>
<li>
The Second List
<ul>
<li>4.1</li>
<li>4.2</li>
</ul>
</li>
</ul>
</body>
I need to get next separate branches of code:
<body>
<p>Example</p>
<ul>
<li>
The First List
<ul>
<li>1</li>
</ul>
</li>
</ul>
</body>
<body>
<p>Example</p>
<ul>
<li>
The First List
<ul>
<li>2</li>
</ul>
</li>
</ul>
</body>
<body>
<p>Example</p>
<ul>
<li>
The First List
<ul>
<li>3</li>
</ul>
</li>
</ul>
</body>
<body>
<p>Example</p>
<ul>
<li>
The Second List
<ul>
<li>4.1</li>
</ul>
</li>
</ul>
</body>
<body>
<p>Example</p>
<ul>
<li>
The Second List
<ul>
<li>4.2</li>
</ul>
</li>
</ul>
</body>
I am trying that code and getting error "maximum recursion depth exceeded while calling a Python object":
from bs4 import BeautifulSoup
parsed = BeautifulSoup(open("example.html"))
body = parsed.body
def all_nodes(obj):
for node in obj:
print node
all_nodes(node)
print all_nodes(body)
I think that I should explain what I want to do with all this stuff later. I am writing test cases in FreeMind and I am trying to write tool which could create csv table for example with all test cases. But for now I am just trying to get all test cases as texts.