title: how to recursively parse tree of nested comments via selenium?
body: <p>I need to scratch comments and replies to comments with usernames, dates from this <a href="https://tengrinews.kz/kazakhstan_news/bagdat-musin-naznachen-vitse-ministrom-tsifrovogo-razvitiya-408861/" rel="nofollow noreferrer">website</a></p>
  <p>The tree of comments sits inside a div container 'comment-list' and each comment may have a recursive structure(if has replies):</p>
  <p>&quot;comment-list&quot; contains list of &quot;comment-item&quot;.</p>
  <p>each &quot;comment-item&quot; has 4 pieces: metadata(username, time),actual comment,replies</p>
  <ul>
  <li><p>comment-item-content:</p>
  <ul>
  <li>metadata:
  <ul>
  <li> username </li>
  <li> time when posted </li>
  </ul>
  </li>
  <li>div 'comment-text' p ACTUAL COMMENT /p</li>
  </ul>
  <p>if replies exist, repeating comment-item:</p>
  <ul>
  <li>comment-item</li>
  <li>comment-item</li>
  </ul>
  </li>
  </ul>
  <p>Here is the carcas:</p>
  <pre><code>&lt;div class = 'tn-comment-list'&gt;
     &lt;div class ='tn-comment-item'&gt;
        &lt;div class = 'tn-comment-item-content'&gt;
           &lt;div class = 'tn-comment-item-content-metadata'&gt; 
              &lt;span class = 'tn-user-name'&gt;username 1 &lt;/span&gt;
              &lt;time&gt; july 20 2020 18:02 &lt;/time&gt;
           &lt;/div&gt;
           &lt;div class = 'tn-comment-item-content-text'&gt;
              &lt;p&gt; bla bla comment 1 &lt;/p&gt;
           &lt;/div&gt;
           &lt;div class = 'tn-comment-item'&gt;... &lt;/div&gt; //reply1
           
           &lt;div class = 'tn-comment-item'&gt;... &lt;/div&gt;//reply 2
           
        &lt;/div&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Instead of doing recursively, i tried to just find all the elements that are comments (comment-item) , regardless of whether they are answers or not.</p>
  <pre><code>from selenium import webdriver
  
  news_url = 'https://tengrinews.kz/kazakhstan_news/strogiy-karantin-vvodyat-v-mangistauskoy-oblasti-408772/'
  
  driver = webdriver.Chrome()
  driver.get(news_url)
  
  comments_list = driver.find_elements_by_xpath(&quot;//div[@class='tn-comment-item']&quot;)
  print(type(comments_list))
  print('length of comments %d ' % len(comments_list))
  </code></pre>
  <p>The length of comments_list is 21, but i dont know how to traverse thru it. Plus, I think recursive parsing is still good idea.</p>
  <p>How to parse it recursively and get all comments?</p>