Я новичок в питоне.Почему этот код не печатает лучшие 50 фильмов?
#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup
import warnings
warnings.filterwarnings("ignore", category=UserWarning, module='bs4')
# website
url = "https://www.imdb.com/search/title?release_date="
year = input("Enter you're fav year for movie display: ")
output = url+year
# extracting the info from website
soup = BeautifulSoup(output, "lxml")
# Display the top 50 films
i = 1
movieList = soup.find_all('div', attrs={'class': 'lister-item mode-advanced'})
for x in movieList:
div = x.find('div', attrs={'class': 'lister-item-content'})
print(str(i) + '.')
header = x.findChild('h', attrs={'class': 'lister-item-header'})
print('Movie: ' + str(header[0].findChild('a'))
[0].contents[0].encode('utf-8').decode('ascii', 'ignore')) #and can someone tell me what is this.. because I’m following some guide. And i didn’t understand this line.
i += 1
Мой токовый выход пуст, на терминале ничего не видно.
0/50 [00:00<?, ?it/s]1.
Traceback (most recent call last): File "movie_recom.py", line 26, in <module> print('Movie: ' + str((header[0].findChild('a'))
TypeError: 'NoneType' object is not subscriptable
Мне нужен этот вывод:
Most Popular Feature Films Released 2018-01-01:
1. Movie: Avengers: Infinity War
2. Movie: Venom
3. Movie: A Quiet Place
4. Movie: Black Panther
5. Movie: I Feel Pretty
6. Movie: Deadpool 2
7. Movie: Ready Player One
8. Movie: Super Troopers 2
9. Movie: Rampage
10. Movie: Den of Thieves
и так до 50.
Заранее спасибо.