soup = BeautifulSoup(data, "html.parser") divs = soup.find_all('div', class_='frame ctooltip') 

I get this result here and I need to pull out Hex values ​​from it, preferably somehow grouped in 5 pieces:

 <div class="frame ctooltip"> <div style="background: #0A1C28"></div> <div style="background: #41848F"></div> <div style="background: #72A7A3"></div> <div style="background: #97C0B7"></div> <div style="background: #EEE9D1"></div> </div>, <div class="frame ctooltip"> <div style="background: #F19CA2"></div> <div style="background: #F8D7D0"></div> <div style="background: #FFE9CD"></div> <div style="background: #BFE9FF"></div> <div style="background: #B7D7D9"></div> </div>,......... 

    1 answer 1

     text = """ <div class="frame ctooltip"> <div style="background: #0A1C28"></div> <div style="background: #41848F"></div> <div style="background: #72A7A3"></div> <div style="background: #97C0B7"></div> <div style="background: #EEE9D1"></div> </div>, <div class="frame ctooltip"> <div style="background: #F19CA2"></div> <div style="background: #F8D7D0"></div> <div style="background: #FFE9CD"></div> <div style="background: #BFE9FF"></div> <div style="background: #B7D7D9"></div> </div> """ from bs4 import BeautifulSoup root = BeautifulSoup(text, 'html.parser') for div in root.select('div.frame.ctooltip'): items = [x['style'].split()[-1] for x in div.select('div')] print(items) 

    Console:

     ['#0A1C28', '#41848F', '#72A7A3', '#97C0B7', '#EEE9D1'] ['#F19CA2', '#F8D7D0', '#FFE9CD', '#BFE9FF', '#B7D7D9']