Home python Parser does not work on Python

Parser does not work on Python




If you enable the code, it will work for a couple of seconds, while outputting nothing, and then turns off.
The code must display “Link to video – Link

import requests
From BS4 Import Beautifulsoup
  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 "Link to video - {Video ['Link']}")

Answer 1, Authority 100%

The site is filled dynamically using JavaScript. You do not solve this task to beAutiFulsUp. you need selenium:
How to Poule HTML page with JavaScript in Python 3?
Parsing Dynamic Site Data on Python

Answer 2

I join the answer of the balls. However, I would advise using scrappy . He will be a little faster than selenium
Here you can read the difference between these three instruments:
https : //dev-gang.ru

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions