Answer the question
In order to leave comments, you need to log in
How can you parse reorder links using Beautiful Soup?
===================================================
<html>
<div class="item">
<div class="quality">SD</div>
<div class="link"><a href>"http://link"</div>
<div class="item">
<div class="quality">HD</div>
<div class="link"><a href>"http://link"</div>
<div class="item">
<div class="quality">FullHD</div>
<div class="link"><a href>"http://link"</div>
</html>
===================================================
<html>
<div class="item">
<div class="quality">SD</div>
<div class="link"><a href>"http://link"</div>
<div class="item">
<div class="quality">FullHD</div>
<div class="link"><a href>"http://link"</div>
<div class="item">
<div class="quality">HD</div>
<div class="link"><a href>"http://link"</div>
</html>
===================================================
<html>
<div class="item">
<div class="quality">FullHD</div>
<div class="link"><a href>"http://link"</div>
<div class="item">
<div class="quality">SD</div>
<div class="link"><a href>"http://link"</div>
<div class="item">
<div class="quality">HD</div>
<div class="link"><a href>"http://link"</div>
</html>
===================================================
Answer the question
In order to leave comments, you need to log in
And how do you understand that the right link is in front of you? Look at the name of the quality, and the link below it? Why should other logic be in the code?
sources = {}
for item in items:
quality = item.find('div', {'class': 'quality'}).text
link = item.find('div', {'class': 'link'}).text
sources[quality] = link
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question