Если включить код, то будет работать пару секунд, при этом ничего не выводя, а потом выключится. Код должен вывести "Ссылка на видео - ссылка"
import requests
from bs4 import BeautifulSoup
def parse_of_video():
URL = 'https://www.youtube.com/feed/trending'
HEADERS = {
'User_Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
}
response = requests.get(URL, headers = HEADERS)
soup = BeautifulSoup(response.content, 'html.parser')
items = soup.findAll('div', class_ = 'style-scope ytd-video-renderer')
videos = []
for item in items:
videos.append({
'link': item.find('a', class_ ='yt-simple-endpoint style-scope ytd-video-renderer').get('href')
})
for video in videos:
print(f"Ссылка на видео - {video['link']}")
parse_of_video()