Home > OS >  Why does the parser not output information to the terminal?
Why does the parser not output information to the terminal?

Time:06-20

Good day, I'm new to learning Python from the word at all) The problem lies in the lack of information in the terminal, except for the completion of the code. Can you tell me what the problem is and why the titles of the films are not displayed?

from bs4 import BeautifulSoup
import requests

url = 'https://www.kinoafisha.info/rating/movies/2022/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
films = soup.find_all('div', class_='movieItem_title')
for film in films:
    print(film.text)

Screenshot

CodePudding user response:

Because there are no divs with the class movieItem_title on the webpage (those with the class movieItem_title are <a> tags), only divs with the class movieItem_info.

If you change it to this:

from bs4 import BeautifulSoup
import requests

url = 'https://www.kinoafisha.info/rating/movies/2022/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
films = soup.find_all('a', class_='movieItem_title')
for film in films:
    print(film.text)

It starts printing out:

Своя война: Шторм в пустыне
Аманат
1941. Крылья над Берлином

(and more...)

When you are parsing websites, I recommend using the built-in browser developer tools. They are extremely useful. You should also try going through your code and thinking through all the variants that could go wrong before asking here on StackOverflow.

  • Related