-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrabalhos.py
60 lines (47 loc) · 2.28 KB
/
trabalhos.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
from bs4 import BeautifulSoup
import requests
# Objetivo: De tempo em tempo fazer varredura no site e verificar novos trabalhos
class Trabalhos:
def __init__(self, url='https://www.vintepila.com.br/trabalhos-freelance/?page=2/'):
self.url = url
self.trabalhos = []
self.soup = None
def carregar_trabalhos(self):
try:
response = requests.get(self.url, timeout=10)
if response.status_code == 200:
self.soup = BeautifulSoup(response.text, 'html.parser')
self.trabalhos = self.soup.findAll('a', class_='header')
else:
print(f'Erro ao carregar a página: {response.status_code}')
except requests.exceptions.RequestException as e:
print(f'Erro ao carregar a página: {e}')
def substituir(self, texto: str) -> str:
texto = (texto.strip().replace('ç', 'c').replace('ã', 'a')
.replace('é', 'e').replace('õ', 'o').replace('–', '')
.replace('á', 'a').replace('ú', 'u').replace('í', 'i')
.replace('â', 'a').replace('ô', 'o'))
return texto
def organizar_frase(self, frase: str):
listagem = frase.lower().split()
frase = '-'.join([self.substituir(palavra) for palavra in listagem])
return frase.rstrip('-')
def procurar_trabalho(self, palavra: str):
self.carregar_trabalhos()
if not self.trabalhos:
print('Nenhum trabalho encontrado')
return
encontrou = False # Variável para monitorar se a palavra foi encontrada
for trabalho in self.trabalhos:
if trabalho.text and palavra.lower() in trabalho.text.lower():
encontrou = True
print(trabalho.text, end='\n')
t = self.organizar_frase(trabalho.text)
link = f'Link: https://www.vintepila.com.br/trabalhos-freelance/{t}'
print(link, end='\n')
# Imprime a mensagem de "não encontrado" se nenhum trabalho contiver a palavra-chave
if not encontrou:
print(f'Não encontrado palavra-chave: {palavra}')
if __name__ == '__main__':
trabalho = Trabalhos()
trabalho.procurar_trabalho('dev')