import requests
from bs4 import BeautifulSoup
def is_end_point(page):
if page.find("table") != None:
return True
else:
return False
def print_schools(page):
for i in page.find_all("a"):
print("Школа--> "+i.text)
def parse(URL):
responce = requests.get(URL).text
bs = BeautifulSoup(responce, "lxml")
page_content = bs.find("div", class_="contents")
if is_end_point(page_content):
print_schools(page_content)
else:
#Если страница не содержит адреса школ
links = page_content.find_all("a")
for i in links:
sub_page = requests.get(i.get("href")).text
sub_page = BeautifulSoup(sub_page, "lxml")
sub_page = sub_page.find("div", class_="contents")
if is_end_point(sub_page):
print_schools(sub_page)
else:
pass
if __name__=="__main__":
parse("https://russiaschools.ru/respublika_bashkortostan/")