-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (29 loc) · 1.2 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
from selenium import webdriver
from selenium.common import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("--headless")
drive = webdriver.Chrome(options=options)
while True:
music = input('Digite a música:').strip()
if not music:
print("Nome da música não informado")
else:
drive.get('https://www.letras.mus.br/')
elem = drive.find_element(By.ID, 'main_suggest')
elem.clear()
elem.send_keys(music)
elem.send_keys(Keys.ENTER)
print("Busca feita com sucesso")
elem = drive.find_element(By.XPATH,
'/html/body/div[1]/div[1]/div[1]/div[3]/div/div/div/div/div/div/div/div[5]/div['
'2]/div/div/div[1]/div[1]/div[1]/div[1]/div/a')
elem.click()
print("Página encontra com sucesso")
try:
letra = drive.find_element(By.CLASS_NAME, 'cnt-letra').text
except NoSuchElementException:
letra = drive.find_element(By.CLASS_NAME, 'cnt-trad_l ').text
print(f'Segue a letra: \n{letra}')
break