My work is basically:
-Entering in this website "https://aplicacoes.mds.gov.br/sagirmps/estrutura_fisica/preenchimento_municipio_cras_new1.php"
-Fill the 2 forms (with AC - Acre and Bujari, for example)
-Click on "Dados Detalhados"(detailed data) in the last column of the table generated. (When you click on "Dados Detalhados", it will generate a second table with the data of 1 month per row).
-Access the data generated by the second table clicking in "Visualizar Relatório" in the last column of each row. <---- THATS the data I'm trying to scrape. But it is a dynamic website and I can't get the data just accessing the url2 (when you click in 'Visualizar relatório' the website returns to the initial url but with the tables I want to scrape). Here is the code:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'http://aplicacoes.mds.gov.br/sagirmps/estrutura_fisica/preenchimento_municipio_cras_new1.php'
params ={
'uf_ibge': '12',
'nome_estado': 'AC - Acre'
'p_ibge': '1200138'
'nome_municipio': 'Bujari'
}
r = requests.post(url, params = params, verify = False)
soup = BeautifulSoup(r.text, "lxml")
tables = pd.read_html(r.text)
unidades = tables[1]
print(unidades)
url2 = 'http://aplicacoes.mds.gov.br/sagirmps/estrutura_fisica/rel_preenchidos_cras.php?&p_id_cras=12001301971'
params2 ={
'p_id_cras': '12001301971'
'mes_referencia': '2019-02-01'
}
r2 = requests.post(url2, json = params2, verify = False)
soup2 = BeautifulSoup(r2.text, 'lxml')
soup2
Note that url2 is the url generated when you click in "Dados Detalhados" and it has the 'p_id_cras' as the second dictionary.
params2 should be the dict used to scrape that data I'm talking about. I've tried the commands params, data and json in the second post request, but none of them works.