S
S
Sergey2020-10-21 10:45:49
beautiful soup
Sergey, 2020-10-21 10:45:49

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>
===================================================


How to get the correct links from the desired "quality" class if the output sequence changes with each request above gave an example of the output that needs to be parsed

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-10-21
@soremix

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

D
datka, 2020-10-21
@datka

Loop parse and find links Or parse directly BS4 Documentation<div class="item"><a href>"http://link"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question