from bs4 import BeautifulSoup
html = '''
<div class="item">
<div class="quality">SD</div>
<div class="link"><a href>"http://linksd"</div>
<div class="item">
<div class="quality">HD</div>
<div class="link"><a href>"http://linkhd"</div>
<div class="item">
<div class="quality">FullHD</div>
<div class="link"><a href>"http://linkfullhd"</div>
<div class="item">
<div class="quality">SD2</div>
<div class="link"><a href>"http://linksd"</div>
<div class="item">
<div class="quality">HD2</div>
<div class="link"><a href>"http://linksd"</div>
<div class="item">
<div class="quality">FullHD2</div>
<div class="link"><a href>"http://linksd"</div>
</html>
</tr>
'''
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('div', class_='item')
q = {}
for item in items:
ql = item.find('div', class_='quality').get_text()
links = item.find('a').get_text()
q[ql] = links
print(q)
import re
txt = "первый юзер: [12344554788|John Doe] второй юзер: [09876654|Jane Doe] и остальные"
x = re.findall("\[(.*?)\]", txt)
for listX in x:
users = listX.split('|')
print("<a href='https://vk.com/"+users[0]+"'>"+users[1]+"</a>")
<a href='https://vk.com/12344554788'>John Doe</a>
<a href='https://vk.com/09876654'>Jane Doe</a>
[Finished in 0.1s]