TypeError: 'NoneType' object is not subscriptable, библиотеки: requests и bs4

выдаётся ошибка:

Traceback (most recent call last):
  File "C:\Users\Artyom\PycharmProjects\pythonProject2\main.py", line 11, in <module>
    print(listing)[i]
    ~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable  

Мой код:

import requests
from bs4 import BeautifulSoup

response = requests.get('http://www.columbia.edu/~fdc/sample.html')
response = response.content
html = BeautifulSoup(response, 'html.parser')
listing = list(html.find_all('h3'))
count = int(len(listing))

for i in range(0, count):
    print(listing)[i]
    print('-----------------------------------------------------------------------------------------------------------')

Не понимаю в чём проблема


Ответы (1 шт):

Автор решения: Namerek

Как то у Вас все не просто:

import requests
from bs4 import BeautifulSoup

response = requests.get('http://www.columbia.edu/~fdc/sample.html')
html = BeautifulSoup(response.content, 'html.parser')

print(
    *map(lambda x: x.get_text(strip=True), html.find_all('h3')), 
    sep='\n-----------------------------------------------------------------------------------------------------------\n'
)
→ Ссылка