def test_page_count():
    driver = Chrome('selenium/chromedriver.exe')

    driver.get(
        'https://gorod.mos.ru/index.php?show=problem&'
        f'tab={"solvedProblems"}&zone=101&district={102}&m={6}&y={2012}')
    print(count_pages(driver))

    driver.get(
        'https://gorod.mos.ru/index.php?show=problem&'
        f'tab={"solvedProblems"}&zone=101&district={102}&m={6}&y={2016}')
    print(count_pages(driver))

    driver.close()
Example #2
0
def read_all_pages(city_oktmo, day):
    link = get_link(city_oktmo, day, page=1)
    request = requests.get(link, headers=request_header)
    html_page = html.fromstring(request.content)

    try:
        # Read first page
        read_page(html_page, city_oktmo)
    except Exception as e:
        print(f'Exception at oktmo={city_oktmo}, day={day}, page={1}:', e)

    # Check if there are other pages and read them
    pages_amount = count_pages(html_page)

    for page in range(2, pages_amount + 1):
        link = get_link(city_oktmo, day, page)
        request = requests.get(link, headers=request_header)
        html_page = html.fromstring(request.content)

        try:
            read_page(html_page, city_oktmo)
        except Exception  as e:
            print(f'Exception at oktmo={city_oktmo}, day={day}, page={page}:', e)