-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (43 loc) · 2.33 KB
/
main.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from time import sleep
import write_file
nome_do_curso = "engenharia-de-software" #altere aqui
################################ NAVEGANDO ATÉ A PÁGINA #################################
url = "https://carreiras.pucrs.br/Oportunidades"
navegador = webdriver.Chrome()
navegador.get(url)
# Espera pagina carregar
sleep(10)
################################ SELECIONANDO CURSO E ENVIANDO #################################
# Seleciona curso engenharia mecânica
curso_select = Select(navegador.find_element(By.ID, "CursoNome"))
curso_select.select_by_value(nome_do_curso) #seleciona curso
# sleep(1)
# Checa se o curso esta realmente escolhido
# if curso_select.first_selected_option.get_attribute("value") != "engenharia-de-software":
# curso_select.select_by_value("engenharia-de-software")
# Scrolla para botao ficar clicavel e depois envia
navegador.execute_script("window.scrollBy(0, 80);")
botao_enviar = navegador.find_element(By.CLASS_NAME, "vagas-enviar")
botao_enviar.click()
# Espera próxima pagina carregar
sleep(5)
################################ ITERANDO SOBRE AS VAGAS #################################
h3_elements = navegador.find_elements(By.CSS_SELECTOR, ".oportunidade-item h3") # titulo das vagas / elemento h3
p_elements = navegador.find_elements(By.CSS_SELECTOR, ".oportunidade-item p") # descricao das vagas / elemento p
a_elements = navegador.find_elements(By.XPATH, "//*[@id='lista']/a") # link das vagas / elemento a
_vagas = [h3.text for h3 in h3_elements] # pega todas as vagas
_descricao = [p.text for p in p_elements] # pega todas as descricoes
_hrefs = [a.get_attribute('href') for a in a_elements] # pega todos links
vagas = []
################################ ATRIBUINDO AS VAGAS AO ARRAY #################################
for i, vaga in enumerate(_vagas):
dict = {'indice': i, 'vaga': write_file.substituir_barras(vaga), 'descricao': _descricao[i], 'link': _hrefs[i] }
vagas.append(dict)
print(f'Foram encontradas {len(_vagas)} vagas.')
################################ ESCREVENDO OS TXT DAS VAGAS #################################
for vaga in vagas:
write_file.escrever_arquivo(vaga)
navegador.quit()