V
V
Vofanchik2021-07-07 12:38:03
Python
Vofanchik, 2021-07-07 12:38:03

What is the error in the get (requests module) request (can't find the page)?

I want to automate the work in procurement. I found an API that will help with this, but it is not enough to get the necessary information, so you need to parse the office. public procurement site (it does not have an api). Having received the contract number, when getting a request in requests, it shows that the page does not exist, although if you drive it into the address bar of the browser, everything is fine. Help me please.

import requests
from pprint import pprint
from bs4 import BeautifulSoup
import re

#prodsearch = {input('Введите поисковой запрос ')}
prodsearch = {'Ван гизон'}
response = requests.get(
    f"http://openapi.clearspending.ru/restapi/v3/contracts/search/?productsearch={prodsearch}&customerregion=77&currentstage=EC&perpage=1&sort=-signDate")

#pprint(response.json())

for contracts in response.json()['contracts']['data']:
    regnum = contracts['regNum']
    print(regnum)
    pprint(contracts['suppliers'][0]['organizationName'])
    print(contracts['contractUrl'])
    payload = {'contractReestrNumber': regnum}
    response_2 = requests.get('https://zakupki.gov.ru/epz/contract/printForm/view.html?', params = payload)
    response_2.encoding = 'utf-8'
    pprint(response_2.text)

    print(contracts['contractUrl'])
    for itera, products in enumerate(contracts['products']):
        pprint(products['name'])
        if itera == 5:
            break
    print('_' * 100)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-07-07
@Vofanchik

You need to pass the user agent and other headers in the request (you can see them in your browser's dev tools)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question