-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.py
74 lines (54 loc) · 2.03 KB
/
index2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
goiania = {"estado": "go", "cidade": "goiania"}
jucurutu = {"estado": "rn", "cidade": "jucurutu"}
estado = input("Estado: ")
if estado.lower() == "goiania":
estado = goiania["estado"]
cidade = goiania["cidade"]
elif estado.lower() == "jucurutu":
estado = jucurutu["estado"]
cidade = jucurutu["cidade"]
else:
cidade = input("Cidade: ")
print("Estado:", estado)
print("Cidade:", cidade)
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome()
driver = webdriver.Chrome(options=chrome_options)
driver.implicitly_wait(10)
url = f'https://cidades.ibge.gov.br/brasil/{estado}/{cidade}/panorama'
driver.get(url)
try:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "tr.lista__cabecalho"))
)
colunas = driver.find_elements(By.CSS_SELECTOR, "th.lista__titulo")
dados = {}
for coluna in colunas:
categoria = coluna.text.strip()
coluna.click()
WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, "tr.lista__indicador"))
)
elementos_listas = driver.find_elements(By.CSS_SELECTOR, "tr.lista__indicador")
valores = []
for elemento in elementos_listas:
valor = elemento.find_element(By.CLASS_NAME, "lista__valor").text.strip()
valores.append(valor)
dados[categoria] = valores
df = pd.DataFrame(dados)
finally:
#pra vc buscar o valor específico passando posição
valor_territorio = df.iloc[30]['TERRITÓRIO']
print("O território é de: ",valor_territorio)
valor_edu = df.iloc[13]['EDUCAÇÃO']
print("Escolas: ",valor_edu)
valor_pib = df.iloc[15]['ECONOMIA']
print("Valor do PIB: ",valor_pib)
driver.quit()