The only automatic way to create a site map is to know the structure of your site and write a program that is based on this knowledge. Just link crawling usually doesnโt work, because links can be between any pages so that you get a graph (i.e. Connections between nodes). It is not possible to convert a graph to a tree in the general case.
So, you must determine the structure of your tree yourself, and then scan the corresponding pages to get the page titles.
As for โbut it only works for three levelsโ: three levels are more than enough. If you try to create more levels, your site map will become unusable (too big, too wide). Nobody wants to download a 1MB Sitemap, and then scroll through 100,000 link pages. If your site is growing so much that you should do some kind of search.
source share