'POST requests gives me an empty result

For practicing purposes I'm trying to retrieve data from https://www.ruc.com.py/ by posting the number 1000000

At first it retrieved a "no access" message so I added headers and that solved it. But now it just brings a blank result, I was expecting to get a the name that corresponds with the input 1000000

This is my code:

import requests

headers = {
'referer': 'https://www.ruc.com.py/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36',
'x-requested-with': 'XMLHttpRequest'
}

num=str(1000000)

url = 'https://www.ruc.com.py/index.php/inicio/consulta_ruc'
response = requests.post(url , headers=headers, data=num)

print (response.text)


Solution 1:[1]

Had a look into the network tab from the website and found out that the POST payload requires the search to be on the form field buscar

enter image description here

With this, just had to do this small change to your code to actually send the payload with the expected data structure:

import requests

headers = {
'referer': 'https://www.ruc.com.py/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36',
'x-requested-with': 'XMLHttpRequest'
}

data={"buscar": 1000000}

url = 'https://www.ruc.com.py/index.php/inicio/consulta_ruc'
response = requests.post(url, headers=headers, data=data)

print(response.json())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 luigibertaco