1
1
1HAWK12021-09-27 21:55:12
Python
1HAWK1, 2021-09-27 21:55:12

The code doesn't work. What to fix?

I am writing a music parser for myself. The code doesn't work. Displays successful execution, but does not display the required information.

from bs4 import BeautifulSoup
import requests

def parse():
    URL = 'https://pixabay.com/music/'
    HEADERS = {
        'User_Agent': 'Chrome: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'
    }
    response = requests.get(URL, headers = HEADERS)
    soup = BeautifulSoup(response.content, "html.parser")
    items = soup.findAll('article', class_ = 'audio-reactive-track collapsed')
    musics = []

    for item in items:
        musics.append({
            'title': item.find('a', class_ = 'name').get_text(strip = True)
        })

        for music in musics:
            print(music['title'])

parse()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-09-27
@1HAWK1

Display the resulting page code on the screen, you will see the presence of cloudflare. Then look for workarounds, or write your own

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question