title: Creating Relationship Between Two Separate Tags -- Python / BeautifulSoup
body: <p>I'm trying to create a relationship between two separate tags on an website.  The website has one massive div with tons of tags inside.  I'm particularly interested in the text between three sets of tags, the b tags, the li tags, and the  tags that are inside the div tags INSIDE the main .  To clear this up, here's the example HTML:</p>
  <pre><code>&lt;h1 class = &quot;article-title&quot;&gt; The Best Names &lt;/h1&gt;
  &lt;div class = &quot;name-content&quot;&gt;
   &lt;b&gt; Start Names &lt;/b&gt; 
   &lt;b&gt; Name 1 &lt;/b&gt;
   &lt;ul&gt;
     &lt;li&gt; &quot;Name 1 is great because&quot; &lt;/li&gt;
     &lt;li&gt; &quot;Name 1 is awesome because&quot; &lt;/li&gt;
   &lt;/ul&gt;
   &lt;b&gt; Name 2 &lt;/b&gt;
   &lt;ul&gt;
    &lt;li&gt; Name 2 is great because&quot; &lt;/li&gt;
   &lt;/ul&gt;
   &lt;div class &quot;separator&gt;
    &lt;a href=&quot;link-to-image&gt;
   &lt;/div&gt;
    &lt;ul&gt;
     &lt;li&gt; etc etc&lt;/li&gt;
   &lt;b&gt; End of Names &lt;/b&gt;
  </code></pre>
  <p>I've stored the text between all li tags and the text between all b tags inside soup objects</p>
  <pre><code>all_b_tags = newSoup.find_all('b')
  all_li_tags = newSoup.find_all('li')
  for liTag in all_li_tags:
    liData.append(liTag.text.strip())
  for bTag in all b_tags
    bData.append(bTag.text.strip())
  </code></pre>
  <p>Now, I want to create a relationship here where I sort the text between li tags and the b tags (Every name has x amount of information).  So I should have a list that will store a name, then store however many lines (li tags) until it reaches the next name.  I've created a list of a bunch of names that I'm using.</p>
  <pre><code>names_to_list = bData[bData.index('Start Names') + 1:bTags.index('End of Names')]
  name_data = liData[liData.index('Start of li') + 1:bData.index('End of Names')]
  </code></pre>
  <p>This is obviously the issue.  I don't know how to only get the li tags that I want but also store information until I hit another name, then create another name.  I'm assuming I should have a &quot;person&quot; object that has all the text I want (both the name and however much data about that name) but I don't know how to parse through this correctly.</p>