Найти - Пользователи
Полная версия: Ошибка AttributeError: 'NoneType' object has no attribute 'find_all' - BeautifulSoup - find_all
Начало » Python для новичков » Ошибка AttributeError: 'NoneType' object has no attribute 'find_all' - BeautifulSoup - find_all
1
mdf
Добрый день!
Пытаюсь парсить страницу
 soup=BeautifulSoup(html, 'lxml')
hlPage=soup.find('div', class_='paginator').find_all('a')[-2].get('href')
Получаю ошибку:
AttributeError: ‘NoneType’ object has no attribute ‘find_all’
Непойму, что не так ? (
ZerG
Покажите весь код
mdf
Вот примерно такой код:
 import requests
from bs4 import BeautifulSoup
import csv
import codecs
import random 
import time
data = []
def get_html_page(url):
    r=requests.get(url)
    return r.text
def get_max_page(html):
    soup=BeautifulSoup(html, 'lxml')
    #нахожу блок с перечнем страниц сохраняю в hpages
    hlPage=soup.find('div', class_='paginator').find_all('a')[-2].get('href')
    print (hlPage)
    print ('OK')
    max_page=1
    return int(max_page)
def main():
    listURL=['https://www.kn.kz/karaganda/prodazha-odnokomnatnyh-dvuhkomnatnyh-trehkomnatnyh-chetyrehkomnatnyh-kvartir/',
             'https://www.kn.kz/zhezkazgan/prodazha-odnokomnatnyh-dvuhkomnatnyh-trehkomnatnyh-chetyrehkomnatnyh-kvartir/'
             ]
    rootURL='https://www.kn.kz'   
#    startURL='https://www.kn.kz/karaganda/prodazha-odnokomnatnyh-dvuhkomnatnyh-trehkomnatnyh-chetyrehkomnatnyh-kvartir/?'
    page_label='/page/'
    
    for startURL in listURL:
        max_page=get_max_page(get_html_page(startURL)) ## получаю кол-во страниц для отфильнованного списка объявлений на сайте
        print (startURL)
        #print(max_page)
        #time.sleep(random.randint(7,16))
        
    
if __name__ == '__main__':
    main()
FishHook
mdf
Получаю ошибку:
AttributeError: ‘NoneType’ object has no attribute ‘find_all’


The only difference is that find_all() returns a list containing the single result, and find() just returns the result.
If find_all() can’t find anything, it returns an empty list. If find() can’t find anything, it returns None:
mdf
FishHook
Млин - спасибо. Затупил - по второму адресу не возвращается результатов )
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB