📜 ⬆️ ⬇️

We get USRN extracts from Rosreestr, bypassing api. Expectations in python, square millimeters in Rosreestr

Not the first acquaintance with the portal Rosreestra


Any lawyer has ever addressed a request to the Rosreestr (Federal Service for State Registration, Cadastre and Cartography). The times when for a request it was necessary to flee to the department of Rosreestr and submit a request on paper are a thing of the past. Rosreestr launched several online services that can be used without leaving home. These services include the request for an extract from the Unified State Register of Real Estate. Official site to get started.

Anyone who has already managed to work with the site, it is known that to obtain an extract from the Register, which will contain information not only about the general characteristics of the object, but also about the copyright holder of the object, you need to go to the personal account of the Federal Registration Service.

Perhaps this is a convenient way to get one or more statements. However, what to do if you need a package of USRN statements? Suppose you are working with real estate or owning a number of objects, the total number of which is more than 10. As a general rule, you should receive an extract from the USRN at least once a year in order to have time to respond in a legal way to undesirable changes in Rosreestr, if they arise besides yours will.
')

You can manually submit requests through your personal account, or you can use the Rosreestr api. The first option is extremely tedious. In addition to the Rosreestra online service itself, it works very slowly with constant freezes, it also invites the average user to enter a whole arsenal of fields for the object when submitting each request. For example, a request for a land plot:


That is, to find out information about the object and get an extract on it, physical. the person must already know all the characteristics of the object! And each time you request information, you must fill in all fields. What can I say, very uncomfortable. Thank you for at least providing that the land can be measured in square millimeters.

The second option for obtaining extracts from the USRN is api Rosreestr. Api is a set of software instructions, according to which your software part and part of the Federal Registration Service share information without your participation. A handy thing if everything works correctly. And one could finish.

However, if you look at the page where Rosreestr explains how to implement a convenient api, it becomes uneasy.

The document with the description is available here - rosreestr.ru/wps/portal/cc_ib_documents?documentId=1521

It takes only 19 pages, but is written in technical language and says that we can not do without a digital signature. In general, long, incomprehensible and uncomfortable. Let's go a shorter way.

When working with the hanging site Rosreestr we need an understanding of such a Python tool as expectations. The most suitable tool for working with this site, at least at the current stage of development of this service Rosreestr.

When the page is slowly loaded loaded in the browser, elements on this page may appear at different time intervals (or not at all). This makes it difficult to find elements; an ElementNotVisibleException or NoSuchElement exception periodically occurs. Using expectations, we can solve this problem.

Waiting gives a certain time interval between the actions performed - the search for an element or any other operation with an element.

Since we are using the selenium module in our work, we will work with what it offers. Selenium provides two types of expectations - implicit (implicit) and explicit (explicit).

Explicit waiting is the code by which you determine which condition must occur in order for the further code to be executed. Previously, we used time.sleep (), which sets the exact wait time. But this option is not entirely successful. The downside is that if you do not guess the idle time (sleep), the program will crash. There are more convenient methods that can help you write code that expects as much as you need.

Writing a program to work with online Rosreestrom


Let's move on to our program.

Its essence is to go to the site Rosreestr, she logged in through a personal account nat. faces and then began to independently submit requests for extracts from the USRN. Our program will receive the data for the requests from the Excel file (where it is without it). One nuance. On the Rosreestr site, when submitting a request, there is a field with the address of the object. There will be difficulties with it, as the addresses in Rosreestr are instituted in a special way. We'll have to take this into account in the work program.

Let's get started

Before starting, we will prepare an excel spreadsheet with the original data in the following format:


The name of the right holder - the address of the property - the type of object - cadastral number - area. When requesting, we will need all the fields in the table except “number” and “name of the right holder”

Now create a new python file - rosreestr.py. And import the necessary modules:

import webbrowser,time from selenium import webdriver import csv from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import NoSuchElementException import openpyxl 

Open the excel file with real estate data:

 wb = openpyxl.load_workbook('activ2.xlsx') sheet=wb.get_active_sheet() 

We go to the site Rosreestra. Since the very entrance to the site can go with delays, it is necessary to put a wait:

 browser = webdriver.Firefox() browser.get ('https://rosreestr.ru/') time.sleep(5) 

Here you can leave just time.sleep 5 seconds. But it is better, using expectations, to write like this:

 browser.implicitly_wait(40) 

Now we need to wait for the appearance of the button to enter the personal account and click on it:

 act = browser.find_element_by_css_selector('#top_panel > a:nth-child(4)') act.click() 

Since the registration in the personal account is done through the portal of state services, the site transfers to the state services and this also happens with a delay, we take this into account:

 browser.implicitly_wait(40) act = browser.find_element_by_id('mobileOrEmail') act.click() 

Now the program is authorized for us on the website of the State Service by entering a username and password (you need to enter your data instead of a username and password):

 i=0 for i in '@mail.ru': act.send_keys(i) time.sleep (0.1) act = browser.find_element_by_id('password') act.click() i=0 for i in '': act.send_keys(i) time.sleep (0.1) act = browser.find_element_by_id('loginByPwdButton') act.click() 

After the program has pressed the enter button, the following window may appear before authorization:



Here you need to select the CSS selector nat. faces. Remember how to do it? Right mouse click on the icon Private person ... - explore the item:



And copy the CSS selector:



We add it to our program:

 act = browser.find_element_by_css_selector('tr.not-border:nth-child(1) > td:nth-child(2) > div:nth-child(2)') act.click() 

Now that we are logged in, the browser will take us from the site of the State Service to the site of the Rosreestr. There, our program should click on the item "Request for information on real estate objects and (or) their owners":



Fill in the appropriate code:

 act = browser.find_element_by_css_selector('div.services-item:nth-child(5) > div:nth-child(1) > span:nth-child(2)') act.click() act = browser.find_element_by_css_selector('div.services-item:nth-child(5) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > a:nth-child(1)') act.click() 

We got to the start page of the request, where they are waiting for us to go through 5 steps:



To go to the second step, tick the page and click next. Denote this in code:

 act = browser.find_element_by_class_name('PGU-LabelIcon') act.click() act = browser.find_element_by_css_selector('#__nextStep') act.click() 

We are on the 2nd step of the site Rosreestr. Here you need to fill in the category of the applicant, all other data is pulled automatically from the State Service. Then click "Next":



In code, it looks like this:

 act = browser.find_element_by_css_selector('#Form7\.step2\.specialDeclarantKind\.code > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(2)') act.click() act = browser.find_element_by_css_selector('#__nextStep') act.click() 

If we run our program, we will most likely get an error:



We handle this error as follows:

 try: act = browser.find_element_by_class_name('PGU-LabelIcon') except: browser.refresh() time.sleep (40) act = browser.find_element_by_class_name('PGU-LabelIcon') 

Now, if a situation arises in which the page does not load, the program will refresh the browser and try again to click on the desired icon. Unfortunately, the expectations do not work here, and you have to use the old, proven time.sleep ().

We are on the third step and it is the most time consuming:



It is necessary to fill in all fields with a “*” sign.

Let's start by entering the object:

 n=1 i=sheet['B'+str(n)].value #i=input(". 1- .2-.3-.4-.5- : ") if i==' ': #1- act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.objectTypeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(2)') act.click() #  act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.area > div:nth-child(1) > div:nth-child(4) > div:nth-child(1) > div:nth-child(2) > input:nth-child(1)') act.click() for i in str(sheet['E'+str(n)].value): act.send_keys(i) time.sleep (0.1) act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.area\.unit > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(2)') act.click() elif i=='': #2- act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.objectTypeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(3)') act.click() act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.objectPurposeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(2)') act.click() elif i=='': #3- act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.objectTypeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(4)') act.click() act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.roomPurposeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(3)') act.click() elif i=='': #4- act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.objectTypeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(5)') act.click() elif i==' ': #5-  act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.objectTypeCode > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(6)') act.click() 

Here we start with a cell in excel, where we have the name of the object. If, for example, a “Land plot” is entered in a cell, then the program is selected by the css-selector corresponding item. Everything also happens with other types of objects in the cell - the program processes them.

Next, the program is clicked on css-selectors cadastral number, type of extract and addresses of objects, these selectors are the same for all objects:

 #  -   excel  act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180 > div:nth-child(1) > div:nth-child(4) > div:nth-child(6) > div:nth-child(2) > input:nth-child(1)') act.click() for i in sheet['C'+str(n)].value: act.send_keys(i) time.sleep (0.1) time.sleep(2) #  act = browser.find_element_by_css_selector('#Form7\.step3\.extractDataRequestType1 > div:nth-child(2) > div:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.opened > div:nth-child(3) > div:nth-child(1) > div:nth-child(2)') act.click() #   act = browser.find_element_by_css_selector('#Form7\.step3\.objectsList\.panel1180\.addressesList\[0\]\.address > div:nth-child(2) > div:nth-child(2) > a:nth-child(1) > span:nth-child(1)') act.click() act = browser.find_element_by_css_selector('.fias_input_search') act.click() 

Now you need to drive the address:

 for i in sheet['D'+str(n)].value: act.send_keys(i) time.sleep (0.1) print(sheet['D'+str(n)].value) i=input(" eneter            enter: ") act = browser.find_element_by_css_selector('a.button-custom:nth-child(2)') act.click() 

The address is taken from column C of the excel table. Here is a pause in the form of the revival of user actions. This is due to the fact that the address in Rosreestre may differ from the one that you have and most likely it is. Therefore, the program, having entered the address from the table to the site, will expect the user to press enter in the interpreter to continue further.

The remaining steps on the Rosreestr portal are the least remarkable, there the program simply clicks the buttons on the “Next” portal and sends the request to the Rosreestr:

 #  act = browser.find_element_by_css_selector('#__nextStep > span:nth-child(1)') act.click() #   ,     act = browser.find_element_by_css_selector('#__nextStep > span:nth-child(1)') act.click() time.sleep (1) # ,    act = browser.find_element_by_css_selector('#__nextStep > span:nth-child(1)') act.click() 

At the end of the program, add a browser update:

 browser.refresh() time.sleep (2) 

If the program has worked correctly, then it remains only to start the cycle on all the cells with objects in our excel file. To do this, at the beginning of the block before i=sheet['B'+str(n)].value :

 while True: if n<36: 

and at the end: n+=1 , where n is the number of properties in the excel table.

Fully text, the program can be viewed here .

Source: https://habr.com/ru/post/460040/


All Articles