AttributeError: 'NoneType' object has no attribute 'get' при динамическом переключении страниц парсер

я не понимаю что не так но раз через раз, после нажатия парсером на кнопку more на хакерньюс вылазит это:

Traceback (most recent call last):
  File "D:\_code-trash\p4rsing\hacker news\main.py", line 26, in <module>
    next_page_link = next_page_find.get('href')
AttributeError: 'NoneType' object has no attribute 'get'

вот весь исходник парсера который просто считывает темы и возвращает название с ссылкой:

import requests
from bs4 import BeautifulSoup


page = 0
while True:
    if page == 0:
        data = requests.get('https://news.ycombinator.com/newest')
    else:
        # get the data
        data = requests.get(f'https://news.ycombinator.com/newest{next_page}')
    # load data into bs4
    soup = BeautifulSoup(data.text, 'lxml')

    # get data by looking for each tr
    for tr in soup.find_all('tr', {'class': 'athing'}):
        for td in tr.find_all('td', {'class': 'title'}):
            themes = td.find('a', {'class': 'titlelink'})
            if themes is not None and not 'item?' in str(themes) and 'github.com' in str(themes):
                sublink = themes.get('href')
                theme_title = td.text
                print(f'{theme_title} - \n{sublink}')
                print('===')

    next_page_find = soup.find(class_='morelink')
    next_page_link = next_page_find.get('href')
    next_page = next_page_link[6:]
    page += 1

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