Пытаюсь парсить страницу
soup=BeautifulSoup(html, 'lxml') hlPage=soup.find('div', class_='paginator').find_all('a')[-2].get('href')
AttributeError: ‘NoneType’ object has no attribute ‘find_all’
Непойму, что не так ? (
soup=BeautifulSoup(html, 'lxml') hlPage=soup.find('div', class_='paginator').find_all('a')[-2].get('href')
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()
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:
FishHookМлин - спасибо. Затупил - по второму адресу не возвращается результатов )