def test_read_page(): driver = Chrome('selenium/chromedriver.exe') driver.get('https://gorod.mos.ru/index.php?show=problem') read_page(driver) driver.close()
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)
create_object(**data) elif type == 'read_page': tab = data['tab'] zone = data['zone'] district = data['district'] month = data['month'] year = data['year'] page = data['page'] driver = Chrome('selenium/chromedriver.exe') driver.get('https://gorod.mos.ru/index.php?show=problem' f'&tab={tab}&zone={zone}&district={district}' f'&m={month}&y={year}&page={page}') data['driver'] = driver read_page(**data) driver.close() elif type == 'read_all_pages': driver = Chrome('selenium/chromedriver.exe') data['driver'] = driver read_all_pages(**data) driver.close() elif type == 'read_all_dates': read_all_dates(**data) else: raise Exception with open('error_correction_log.txt', 'r+') as file: