title: Beautifulsoup, grab text with link
body: <p>i'm making a web spider to automate some of my work.
  I have a table with lots of drivers and different version for different operating systems.
  So far everything works fine but i'm having a hard time separating the links for each operating system.
  I'll post part of the html here, but i can't post the whole page.
  The problem is i don't know can i grab each link and the text that's next to it, i can grab all of them but then i don't know what links if for what operating system.</p>
  
  <p>This is the content of one cell in the table, all i need is to get the link along with the OS verstion (win8.1, win10, win7)</p>
  
  <pre><code>&lt;p class="MsoNormal" style="mso-line-height-alt:9.3pt"&gt;&lt;span style="font-size:11.0pt;font-family:&amp;quot;Calibri&amp;quot;,sans-serif;color:#1F497D"&gt;SfP/StP
      &lt;a href="LINK_TO_FILE"&gt;AHWFW0609P_WinB&lt;/a&gt;.zip
      &lt;/span&gt;&lt;span class="MsoHyperlink"&gt;&lt;b&gt;&lt;sup&gt;&lt;span style="font-size:11.0pt;
      font-family:&amp;quot;Calibri&amp;quot;,sans-serif;color:#984806;background:white;text-decoration:
      none;text-underline:none"&gt;Win8.1&lt;/span&gt;&lt;/sup&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:11.0pt;font-family:&amp;quot;Calibri&amp;quot;,sans-serif"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  
  &lt;p class="MsoNormal" style="mso-line-height-alt:9.3pt"&gt;&lt;span style="font-size:11.0pt;font-family:&amp;quot;Calibri&amp;quot;,sans-serif;color:#1F497D"&gt;SfP/StP
      &lt;a href="LINK_TO_FILE"&gt;AHWFW0553P_WinT&lt;/a&gt;&lt;/span&gt;&lt;span style="color:#1F497D"&gt;.&lt;/span&gt;&lt;span style="font-size:11.0pt;font-family:
      &amp;quot;Calibri&amp;quot;,sans-serif;color:#1F497D"&gt;zip&lt;/span&gt;&lt;span class="MsoHyperlink"&gt;&lt;b&gt;&lt;sup&gt;&lt;span style="font-size:11.0pt;font-family:&amp;quot;Calibri&amp;quot;,sans-serif;color:#984806;
      background:white;text-decoration:none;text-underline:none"&gt; Win10&lt;/span&gt;&lt;/sup&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class="MsoHyperlink"&gt;&lt;b&gt;&lt;sup&gt;&lt;span style="color:#984806;background:white;
      text-decoration:none;text-underline:none"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/sup&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
  </code></pre>
  
  <p>here is the code i use to grab the names and the links.</p>
  
  <pre><code>file = open(r"Path to HTML file", 'rb')
  drivers = {}
  rng_lst = [str(x) for x in range(5, 43)]
  
  soup = bs4.BeautifulSoup(file)
  
  table = soup.findAll('table')[0]
  for row in table.findAll('tr'):
      cells = row.findAll('td')
      if len(cells) &gt; 4:
          cell_num = cells[1].get_text(strip=True)
          if any(cell_num == n for n in rng_lst):
              drv_name = cells[2].get_text(strip=True)
              drivers[drv_name] = {'links': []}
              links = cells[4].findAll('a')
              for link in links:
                  drivers[drv_name]['links'].append(link.get('href'))
  </code></pre>