In [ ]:
!pip install selenium
In [1]:
import selenium
from bs4 import BeautifulSoup
In [2]:
from selenium import webdriver as wb
In [3]:
br = wb.Chrome("/Users/allat/Downloads/chromedriver")
In [4]:
br.get("http://www.cikrf.ru/services/lk_address/?do=find_by_uik")
In [5]:
n_uik = 244
reg = "Ивановская область"
In [23]:
uik_field = br.find_element_by_css_selector('#uik')
uik_field.send_keys(n_uik) 
reg_field = br.find_element_by_name("subject")
reg_field.send_keys(reg)
button = br.find_element_by_link_text("Отправить запрос")
button.click() 

soup = BeautifulSoup(br.page_source, 'lxml')

texts = [a.text for a in soup.find_all('p')] 
address = list(filter(lambda x: "Адрес помещения для голосования:" in x, 
       texts))[0]  
In [31]:
br = wb.Chrome("/Users/allat/Downloads/chromedriver")
def get_address(n_uik, reg):
    br.get("http://www.cikrf.ru/services/lk_address/?do=find_by_uik")
    uik_field = br.find_element_by_css_selector('#uik')
    uik_field.send_keys(n_uik) 
    reg_field = br.find_element_by_name("subject")
    reg_field.send_keys(reg)
    button = br.find_element_by_link_text("Отправить запрос")
    button.click() 

    soup = BeautifulSoup(br.page_source, 'lxml')

    texts = [a.text for a in soup.find_all('p')] 
    try:
        address = list(filter(lambda x: "Адрес помещения для голосования:" in x, 
           texts))[0]  
    except:
        address = None
    print(n_uik)
    return n_uik, address
    
In [35]:
from time import sleep
res = [] 
uiks = range(200, 211)
for u in uiks:
    res.append(get_address(u, "Ивановская область")) 
    sleep(2) 
200
201
202
203
---------------------------------------------------------------------------
SessionNotCreatedException                Traceback (most recent call last)
<ipython-input-35-f765701778eb> in <module>()
      3 uiks = range(200, 211)
      4 for u in uiks:
----> 5     res.append(get_address(u, "Ивановская область"))
      6     sleep(2)

<ipython-input-31-5f5a5728365b> in get_address(n_uik, reg)
      1 def get_address(n_uik, reg):
----> 2     br = wb.Chrome("/Users/allat/Downloads/chromedriver")
      3     br.get("http://www.cikrf.ru/services/lk_address/?do=find_by_uik")
      4     uik_field = br.find_element_by_css_selector('#uik')
      5     uik_field.send_keys(n_uik)

/anaconda3/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     79                     remote_server_addr=self.service.service_url,
     80                     keep_alive=keep_alive),
---> 81                 desired_capabilities=desired_capabilities)
     82         except Exception:
     83             self.quit()

/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
    155             warnings.warn("Please use FirefoxOptions to set browser profile",
    156                           DeprecationWarning, stacklevel=2)
--> 157         self.start_session(capabilities, browser_profile)
    158         self._switch_to = SwitchTo(self)
    159         self._mobile = Mobile(self)

/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in start_session(self, capabilities, browser_profile)
    250         parameters = {"capabilities": w3c_caps,
    251                       "desiredCapabilities": capabilities}
--> 252         response = self.execute(Command.NEW_SESSION, parameters)
    253         if 'sessionId' not in response:
    254             response = response['value']

/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

SessionNotCreatedException: Message: session not created
from disconnected: Unable to receive message from renderer
  (Session info: chrome=73.0.3683.103)
  (Driver info: chromedriver=2.44.609545 (c2f88692e98ce7233d2df7c724465ecacfe74df5),platform=Mac OS X 10.13.6 x86_64)
In [ ]: