S
S
Sabrjkee2019-04-10 09:05:06
Python
Sabrjkee, 2019-04-10 09:05:06

Python POST request getting wrong result?

Good afternoon, I'm trying to get data by POST request from the site , I looked at how the request is formed in the browser, after entering data into the filter and tried to write a request

import requests

test = 'elementID=find_unp_reestr&begin_between=1&end_between=10&unp=490822627'

r = requests.post("http://www.portal.nalog.gov.by/ngb/data/", data=test)

print(r.text)

when executed I get the following
python3 parser.py 
<div id="null_error" onclick="ShowError('null')" class="error_message"><div style="width: 32px; height: 32px;">&#160;</div><div style="width:640px; height:480px; overflow:auto;" ><font style="font-family: Arial;     font-size: 12px;        font-weight: bold;">Параметры элемента</font><br/><textarea style="width: 610px; height: 200px;" >{index=0, elementID=null, xslindex=0}</textarea><br /><font style="font-family: Arial; font-size: 12px;        font-weight: bold;">Параметризованный запрос</font><br/><textarea style="width: 610px; height: 200px;" >null</textarea><br /><font style="font-family: Arial;    font-size: 12px;        font-weight: bold;">Результат выполнения запроса в XML виде</font><br/><textarea style="width: 610px; height: 200px;" ><?xml version="1.0" encoding="UTF-8"?><root></root></textarea><br /><font style="font-family: Arial;      font-size: 12px;        font-weight: bold;">Результат XML преобразования</font><br/><textarea style="width: 610px; height: 200px;" ></textarea><br /><br /></div></div>

although (sort of) should get this +
<tbody><tr><td>490822627</td><td>Общество с ограниченной ответственностью "Джог и Ко"</td><td>23.04.2014</td><td>Абзац 6 п.1.1 Указа 488</td><td/><td/></tr></tbody>

Tell me what I'm doing wrong or maybe I need to use another library?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-04-10
@Sabrjkee

data in post requests is passed in json

>>> import requests
>>> test = {'elementID': 'find_unp_reestr', 'begin_between': '1', 'end_between': '10', 'unp': '490822627'}
>>> r = requests.post("http://www.portal.nalog.gov.by/ngb/data/", data=test)
>>> r.text
'<tbody><tr><td>490822627</td><td>Общество с ограниченной ответственностью "Джог и Ко"</td><td>23.04.2014</td><td>Абзац 6 п.1.1 Указа 488</td><td/><td/></tr></tbody>'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question