How do I extract a section from html?

I want to create a site with django that has several chapters and sections within each chapter. What I want to be able to do is have a single file per chapter and have django pull sections from that file and display each one as their own page. So if I have 6 chapters then I want 6 html files. This way if I update a chapter file, it will update all those sections instead of having to update each section as it’s own file.
Any ideas?

What is the format of the data in the file? Are there some obvious markers that are available for you to identify the beginning of a chapter?

You have all the tools in Python at your disposal to manipulate text. For example, if it’s a simple text file, you have the re library for finding those markers. Or, if the chapters are stored as HTML, you have BeautifulSoup available for finding the right divs.

Once you figure out how to find the right section in the chapter you want to display, then that’s the text to render for the current request.

1 Like

Sounds like Beautiful Soup is the answer! Thanks!